sanity-io / plugin-kit

Enhanced Sanity.io plugin development experience.
MIT License
76 stars 7 forks source link

npm run link-watch produces "`type` in `./package.json` must be of type 'commonjs' | 'module' (received undefined)" #59

Open wildseansy opened 1 year ago

wildseansy commented 1 year ago

When running the README.md quick run steps, the package.json doesn't seem to be properly configured.

# Initialize a new plugin (outside of your Sanity studio folder)
npx @sanity/plugin-kit init sanity-plugin-testing-it-out

# Make your plugin linkable, and compile an initial version
cd sanity-plugin-testing-it-out
npm run link-watch

npm run link-watch produces

[error] `type` in `./package.json` must be of type 'commonjs' | 'module' (received undefined)

To fix this

  1. The plugin template package.json needs "type": "module" added
  2. "exports": {
    ".": {
      "types": "./lib/src/index.d.ts",
      "source": "./src/index.ts",
      "import": "./lib/index.esm.js",
      "require": "./lib/index.js", // Update to .cjs
      "default": "./lib/index.esm.js"
    },
    "main": "./lib/index.js", //update to .cjs
EmilyYond commented 8 months ago

Thank you @wildseansy for this, this is still an issue but this has resolved this error for me. However, I immediately get another error

[error] exports["."]: the `types` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported

I'm not very familiar with how to set up a typescript package, so I'm not sure how to resolve this? Could you give me a hand?