I'm using tiptap in my Quasar app with the node CodeBlockLowlight enabled.
Running the dev server
works just fine with quasar dev --mode ssr --port 9000
. THe project builds and I'm able to work on my project without any issues.
Now, whenever I try to start the node server with the following command ENV_FILE=test quasar build --mode ssr --port 3000 && node dist/ssr/index.js
it gives the following errors:
internal/modules/cjs/loader.js:1102
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/whatever/devotto/devotto.com/node_modules/lowlight/lib/core.js
require() of ES modules is not supported.
require() of /home/whatever/devotto/devotto.com/node_modules/lowlight/lib/core.js from /home/whatever/devotto/devotto.com/dist/ssr/server/server-entry.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename core.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/whatever/devotto/devotto.com/node_modules/lowlight/package.json.
Here is my package.json
{
...
"dependencies": {
"@quasar/extras": "^1.0.0",
"@tiptap/extension-code-block-lowlight": "^2.0.0-beta.209",
"lowlight": "^2.8.0",
"@tiptap/vue-3": "2.0.0-beta.204",
}
}
What I have tried
After reading the following resources:
- https://github.com/wooorm/lowlight/issues/37
- https://bobbyhadz.com/blog/error-err-require-esm-must-use-import-to-load-es-module
- Importing in Node.js: error "Must use import to load ES Module"
I have:
- tried to lower the version of
lowlight
all the way to1.20.0
- tried to add
"type": "module"
to mypackage.json
So far I wasn't able to build my project and start a node server so I can run my E2E tests.
Why am I getting this error and how I can solve it?