I am building a CodeMirror-Yjs-editor. I followed the example in y-codemirror.next. But when I tried to rollup the JS, I got the error in the title.
I tried to change dependency version but still could not get it working. Please help.
Any help is appreciated.
Rollup command:
npm run dist
Error:
[!] RollupError: "default" is not exported by "node_modules/simple-peer/simplepeer.min.js", imported by "node_modules/y-webrtc/src/y-webrtc.js".
https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module
node_modules/y-webrtc/src/y-webrtc.js (16:7)
14:
15: import * as Y from 'yjs' // eslint-disable-line
16: import Peer from 'simple-peer/simplepeer.min.js'
^
17:
18: import * as syncProtocol from 'y-protocols/sync'
at error (/var/www/websocket_live/codemirror.next/node_modules/rollup/dist/shared/rollup.js:349:30)
at Module.error (/var/www/websocket_live/codemirror.next/node_modules/rollup/dist/shared/rollup.js:15093:16)
at Module.traceVariable (/var/www/websocket_live/codemirror.next/node_modules/rollup/dist/shared/rollup.js:15518:29)
... ...
My package.json
file:
{
"name": "CodeMirror-Yjs-editor",
"version": "1.0.0",
"description": "",
"main": "codemirror.js",
"scripts": {
"clean": "rm -rf dist",
"dist": "npm run clean && rollup -c --bundleConfigAsCjs && tsc",
"watch": "rollup -wc",
"lint": "standard && tsc",
"start": "concurrently 'http-server -o index.html' 'npm run watch'"
},
"dependencies": {
"@codemirror/lang-javascript": "^6.0.2",
"codemirror": "^6.0.1",
"y-codemirror.next": "^0.3.2",
"y-webrtc": "^10.2.5",
"yjs": "^13.5.41"
},
"devDependencies": {
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"concurrently": "^5.3.0",
"http-server": "^14.1.0",
"jsdom": "^22.1.0",
"rollup": "^3.27.2",
"standard": "^14.3.4",
"typescript": "^3.9.10"
}
}
Update:
rollup.config.js
import babel from "@rollup/plugin-babel";
import {nodeResolve} from "@rollup/plugin-node-resolve";
export default {
input: "./codemirror.js",
output: {
file: "./cm6.bundle.js",
format: "umd"
},
plugins: [babel(), nodeResolve()]
}
After finding solution for a long time, I will post my own solutions. Hope this will help someone.
Short Story: Change rollup plugin orders. Try to move them one by one and it fixed my problem.
Long story in a short version:
Since the time I posted the question, I have made many changes to the project and the rollup config file is looked a little different.
I have searched the web for solution for a long time and I found that someone fixed the problem by moving the plugins in rollup config file around and the problem is gone. So I gave it a try.
Here is my rollup config file,
What I have done is moving
commonjs(), globals(),
from the top to the bottom in the plugin array. And it works when it stops at this location. I could not explain why, because I have not read the full document (and source code) of rollup and its plugins. But it seems that when working on the JS source code, rollup does things in steps. If the actions are in the correct order, then it will work. I think read more will definitely helps. And I will find time to do that.