codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.44k stars 343 forks source link

Error: [commonjs--resolver] Missing "./" specifier in "xyz" package #1356

Closed mcmxcdev closed 3 months ago

mcmxcdev commented 3 months ago

Describe the issue

We have been using codemirror without any issues for a couple months now in a Sveltekit project, but when trying to update our reusable packages/ui package.json to use exports like in the example on turborepo, the Vite build starts erroring with the following stacktrace:

✓ 1227 modules transformed.
x Build failed in 14.86s
error during build:
Error: [commonjs--resolver] Missing "./" specifier in "xyz" package
    at e (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:47465:25)
    at n (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:47465:627)
    at o (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:47465:1297)
    at resolveExportsOrImports (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:48144:20)
    at resolveDeepImport (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:48163:31)
    at tryNodeResolve (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:47888:20)
    at Object.resolveId (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:47649:28)
    at Object.handler (file:///home/user/org/repo/node_modules/.pnpm/vite@5.1.6/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:67254:19)
    at file:///home/user/org/repo/node_modules/.pnpm/rollup@4.12.1/node_modules/rollup/dist/es/shared/node-entry.js:19571:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/user/org/repo/node_modules/.pnpm/rollup@4.12.1/node_modules/rollup/dist/es/shared/node-entry.js:19471:28)
/home/user/org/repo:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  org/repo@1.0.0 build: `vite build`
Exit status 1

I was able to pinpoint it down to codemirror by running vite build multiple times with different files referenced and commented in/out. Our other apps in the monorepo not using codemirror still build successfully.

Not sure how to solve this, but it seems that codemirror would need to move to ESM to get rid of the error?

Browser and platform

Version 1.63.169 Chromium: 122.0.6261.111 (Official Build) (64-bit), Ubuntu 23.10

Reproduction link

No response

marijnh commented 3 months ago

CodeMirror provides ESM packages. Given the ridiculous error message, I'm inclined to believe this is a bug in vite or some other part of your toolchain. Feel free to reopen if you have something more actionable, though.

XiSenao commented 3 months ago

I guess it might be a problem caused by the non-compliant exports field. Try loading the package in the following way:

"exports": {
    ".": {
      "types": "./index.ts",
      "svelte": "./index.ts",
       // add field
      "default": "./index.ts"
    }
  },
mcmxcdev commented 3 months ago

Thanks for the suggestion! I just tried that, but it still fails with the same error message unfortunately.