Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Error: Cannot find module '../schemas' #266

Open
ollebergkvist opened this issue May 20, 2022 · 5 comments
Open

Error: Cannot find module '../schemas' #266

ollebergkvist opened this issue May 20, 2022 · 5 comments

Comments

@ollebergkvist
Copy link

ollebergkvist commented May 20, 2022

I'm getting this error running Next, sanity blog example with the codegen.

sanity-codegen.config.ts

const config: SanityCodegenConfig = {
  schemaPath: "./blog/schemas",
  outputPath: "./schema.ts",

  // NOTE: The CLI ships with a pre-configured babel config that shims out
  // the Sanity parts system. This babel config does not read from any
  // `.babelrc` or `babel.config.js`. You can only configure extra babel
  // options here.
  // babelOptions: require('./.babelrc.json'), // (optional)
};

Error message:

npx sanity-codegen                   
Error: Cannot find module '/Users/user/Documents/dev/sanity/sanity-codegen-test/blog/schemas'
Require stack:
- /Users/user/Documents/dev/sanity/sanity-codegen-test/node_modules/sanity-codegen/cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at cli (/Users/user/Documents/dev/sanity/sanity-codegen-test/node_modules/sanity-codegen/cli.js:100:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/user/Documents/dev/sanity/sanity-codegen-test/node_modules/sanity-codegen/cli.js'
  ]
}

Dependencies:

"dependencies": {
    "next": "12.1.6",
    "next-sanity": "^0.5.2",
    "prettier": "^2.6.2",
    "react": "18.1.0",
    "react-dom": "18.1.0",
    "sanity": "^2.29.3",
  },

"devDependencies": {
    "@babel/core": "^7.18.0",
    "@babel/preset-env": "^7.18.0",
    "@babel/preset-react": "^7.17.12",
    "@babel/preset-typescript": "^7.17.12",
    "@sanity/types": "^2.29.5",
    "eslint": "8.15.0",
    "eslint-config-next": "12.1.6",
    "jsdom": "^19.0.0"
    "sanity-codegen": "^0.9.8"
  }
@ollebergkvist
Copy link
Author

I tried to run the package with the official Vercel example as well, same issue:

https://github.com/vercel/next.js/tree/canary/examples/cms-sanity

@eldoy
Copy link

eldoy commented Jun 13, 2022

Use this line in the config:

schemaPath: './studio/schemas/schema.js',

The script is looking for the file where you run createSchema, just read the source. This fixed it for me.

@ollebergkvist
Copy link
Author

ollebergkvist commented Jun 13, 2022

I added the path to the schema file as well, which now leads to:

/Users/user/Documents/dev/project/snap-system/apps/cms/schemas/schema.ts:1
import schemaTypes from 'all:part:@sanity/base/schema-type'
^^^^^^

SyntaxError: Cannot use import statement outside a module

@adebiyial
Copy link

@ollebergkvist I think it should be /Users/user/Documents/dev/project/snap-system/apps/cms/schemas/schema

@DuEyE
Copy link

DuEyE commented Aug 31, 2022

I got it working in my setup.
Run npx sanity-codegen in the sanity directory.
My utils folder and the babel.config are in the root of the project.
`
import { SanityCodegenConfig } from 'sanity-codegen';

const config: SanityCodegenConfig = {
schemaPath: './schemas/schema.js',
outputPath: '../utils/types/types.ts',

// NOTE: The CLI ships with a pre-configured babel config that shims out
// the Sanity parts system. This babel config does not read from any
// .babelrc or babel.config.js. You can only configure extra babel
// options here.
babelOptions: require('../babel.config.js'), // (optional)
};

export default config;
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants