ESM error
joacub opened this issue · 7 comments
import { yDocToProsemirrorJSON, prosemirrorJSONToYDoc } from 'y-prosemirror';
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'prosemirrorJSONToYDoc' not found. The requested module 'y-prosemirror' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'y-prosemirror';
const { yDocToProsemirrorJSON, prosemirrorJSONToYDoc } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
last version
Too little information was provided. Did it work before? Apparently, you are using esm
to run the code. Lastly, the solution to your problem is in the comment you provided.
Sorry sir, problem was introduced after the import dynamic exports, I think the problem is the exports with the point, you should remove the point and leave only the children. Then will work properly the imports and requires
This line:
"exports": {
".": {
"import": "./src/y-prosemirror.js",
"require": "./dist/y-prosemirror.cjs"
}
},
it should be:
"exports": {
"import": "./src/y-prosemirror.js",
"require": "./dist/y-prosemirror.cjs"
},
This is gonna work.
These lines are equivalent according to the spec. Can you please test whether this works by patching this manually in your_project/node_modules/yjs/package.json
and then running your code again?
yep still not working, I saw the issue, is treating all .js like comonjs, package should have type: "module" as I see you are using the cjs extension for common.
I tested and is working after put the type: module
other approach is if you don't want to mark type:module is use the .mjs extension, but right now is common's all .js extensions as long as you don't mark the package like module type
Right, type: module
was missing as I haven't updated the package in a while. This feature was added after the last refactor of the project.
I release a new package with type: module
which should fix your problem.
Right,
type: module
was missing as I haven't updated the package in a while. This feature was added after the last refactor of the project.I release a new package with
type: module
which should fix your problem.
Thanks so much, we are using this in our website, we are planning to have an online newspaper using this feature for everybody even for the normal users, great utility, thanks for your efforts.