-
-
Notifications
You must be signed in to change notification settings - Fork 599
Description
Describe the bug
Error when starting nodejs application

node_modules/ts-node/dist/index.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@blocknote/core/node_modules/rehype-parse/index.js from node_modules/@blocknote/core/dist/blocknote.umd.cjs not supported.
Instead change the require of index.js in node_modules/@blocknote/core/dist/blocknote.umd.cjs to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (node_modules/ts-node/dist/index.js:851:20)
at node_modules/@blocknote/core/dist/blocknote.umd.cjs:1:99
at Object. (node_modules/@blocknote/core/dist/blocknote.umd.cjs:1:2397)
at require.extensions. [as .js] (node_modules/ts-node/dist/index.js:851:20)
at node_modules/@blocknote/server-util/dist/blocknote-server-util.umd.cjs:1:70
at Object. (node_modules/@blocknote/server-util/dist/blocknote-server-util.umd.cjs:1:487)
at require.extensions. [as .js] (node_modules/ts-node/dist/index.js:851:20)
at Object. (src/yjs.ts:8:23)
at m._compile (node_modules/ts-node/dist/index.js:857:29)
at require.extensions. [as .ts] (node_modules/ts-node/dist/index.js:859:16)
at Object. (src/socket.ts:4:18)
at m._compile (node_modules/ts-node/dist/index.js:857:29)
at require.extensions. [as .ts] (node_modules/ts-node/dist/index.js:859:16)
at Object. (src/index.ts:32:21)
at m._compile (node_modules/ts-node/dist/index.js:857:29)
at require.extensions. [as .ts] (node_modules/ts-node/dist/index.js:859:16)
at phase4 (node_modules/ts-node/dist/bin.js:466:20)
at bootstrap (node_modules/ts-node/dist/bin.js:54:12)
at main (node_modules/ts-node/dist/bin.js:33:12)
at Object. (node_modules/ts-node/dist/bin.js:579:5) {
code: 'ERR_REQUIRE_ESM'
}
[nodemon] app crashed - waiting for file changes before starting...
Error [ERR_REQUIRE_ESM]: require() of ES Module
To Reproduce
Create Node app with package.json and tsconfig.json
{ "name": "App", "version": "0.0.1", "description": "Collaboration Provider Service(Powered by SocketIO & YJS)", "type": "commonjs", "devDependencies": { "@babel/preset-typescript": "^7.22.5", "@types/html-to-text": "^9.0.4", "@types/jest": "^29.5.2", "@types/node": "^20.8.6", "jest": "^29.5.0", "nodemon": "^3.0.1", "swagger-autogen": "^2.23.7", "ts-jest": "^29.1.0", "ts-node": "10.9.1", "tspec": "^0.1.112", "typescript": "^5.2.2" }, "dependencies": { "@blocknote/server-util": "^0.15.3", "@logtail/node": "^0.4.21", "@sentry/node": "^7.103.0", "@socket.io/redis-adapter": "^8.2.1", "@socket.io/sticky": "^1.0.4", "cors": "^2.8.5", "dotenv": "^16.1.4", "express": "^4.17.2", "html-to-text": "^9.0.5", "mysql2": "^2.3.3", "redis": "^4.6.13", "reflect-metadata": "^0.1.13", "sha1": "^1.1.1", "socket.io": "^4.7.2", "typeorm": "0.3.7", "y-socket.io": "^1.1.3" }, "scripts": { "build": "npm run clean && tsc --project ./", "dev": "npm run clean && nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts", "start": "node build/index.js", "test": "jest" } }
{ "compilerOptions": { "lib": [ "es6" ], "target": "es2018", "module": "commonjs", "moduleResolution": "node", "outDir": "./build", "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, "skipLibCheck": true, "esModuleInterop": true, "allowImportingTsExtensions": true }, "exclude": [ "node_modules" ] }
src/index.tsx
`
import "reflect-metadata"
import express, {NextFunction, Request, Response} from "express"
import http, {Server} from "http";
import {ServerBlockNoteEditor} from "@blocknote/server-util";
const app = express()
const server = http.createServer(app);
const defaultBlock: any = [{
type: "paragraph",
content: "",
}]
app.get('/', (req: Request, res: Response, next: NextFunction) => {
const editor = ServerBlockNoteEditor.create();
editor.blocksToYXmlFragment(defaultBlock, doc.getXmlFragment("document-store"))
return response.send('Huh? works..')
})
const startListening = (server: Server, port: number) => {
server.listen(port)
console.log(`Servidor iniciado on port: 3030`);
console.log(`Server started: ${new Date()}`);
}
`
Note: Code is stripped down for simplicity.
Misc
- Node version: 18.18.0
- Package manager: npm 9.8.1
- Browser: N/A
- I'm a sponsor and would appreciate if you could look into this sooner than later 💖