Error while adding a new schema to an existing Sanity dataset

71 Views Asked by At

I am trying to add a new table/schema to an existing sanity dataset using sanity cli, in a Next.js project

Using this command in the cmd:

sanity dataset import portfolio --path=schemas/diploma.js

But this error occurs:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\wrap-ansi\index.js from C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\cliui\build\index.cjs not supported.
Instead change the require of index.js in C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\cliui\build\index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\cliui\build\index.cjs:293:14)
    at Object.<anonymous> (C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\yargs\build\index.cjs:1:60678)
    at Object.<anonymous> (C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\yargs\yargs:3:69)
    at Object.<anonymous> (C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\sanity\lib\_chunks\_internal-f777504c.js:6:13)
    at Object.<anonymous> (C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\sanity\lib\_internal.js:6:17)
    at Object.dynamicRequire (C:\Users\Arotiana\AppData\Local\Yarn\Data\global\node_modules\@sanity\cli\lib\_chunks\getCliConfig-3f875ac6.js:17:15)
    at mergeCommands (C:\Users\Arotiana\AppData\Local\Yarn\Data\global\node_modules\@sanity\cli\lib\_chunks\cli-5477dc77.js:11445:335)
    at Object.runCli (C:\Users\Arotiana\AppData\Local\Yarn\Data\global\node_modules\@sanity\cli\lib\_chunks\cli-5477dc77.js:19287:2106) {
  code: 'ERR_REQUIRE_ESM'
}
PS C:\Users\Arotiana\Documents\DELL KELY\aportfolio\sanity> 

As I read the error, I understand that it indicates that the require() function of an ES module is not supported in my current environment. The error message suggests changing the require() function in C:\Users\Arotiana\Documents\DELL KELY\aportfolio\node_modules\cliui\build\index.cjs to a dynamic import() which is available in all CommonJS modules

And after looking for solution on the web, I found that I should add "type": "module" in my package.json like so

  {
  "homepage": "https://aportfolio.github.io/aportfolio",
  "name": "portfolio-react",
  "version": "0.1.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "predeploy": "yarn dev",
    "deploy": "gh-pages -d build",
    "lint": "next lint"
  },
  "dependencies": {........

Then.... my whole Next.js app canot run

PS C:\Users\Arotiana\Documents\DELL KELY\aportfolio>
                                                     yarn run dev
yarn run v1.22.19
$ next dev
- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- info Loaded env from C:\Users\Arotiana\Documents\DELL KELY\aportfolio\.env
- error Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'C:\Users\Arotiana\Documents\DELL KELY\aportfolio\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///C:/Users/Arotiana/Documents/DELL%20KELY/aportfolio/next.config.js:1:16
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
  type: 'ReferenceError'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS C:\Users\Arotiana\Documents\DELL KELY\aportfolio> 

Someone can help me solve this, please?

0

There are 0 best solutions below