You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/fs-capacitor/dist/index.js from .../server.ts not supported.
Instead change the require of index.js in .../server.ts to a dynamic import() which is available in all CommonJS modules.
...
I am using ts-node/ts-node-dev for the development and here is the tsconfig.json file.
A side note, but you should look at the TS config compilerOptionsmodule and moduleResolution option values you are using; they are outdated. There are "nodenext" and "node16" values which work much better with the way Node.js ESM, package exports, etc. works.
That said, the simple answer is that if your module is CJS then your can't require an ESM module; that's just a limitation of the way CJS and ESM works. ESM can import CJS, but not the other way around (with the exception of dynamic imports). Your source code might look like it's ESM, but if you're compiling it to CJS modules and that's what runs then you will hit problems like this.
The best thing to do is to migrate your project to using proper ESM at runtime; something Node.js is perfectly capable of. Then you can import ESM modules like those exported by fs-capacitor without problems. If you are using TypeScript to compile your source code you should use the file extension .mts.
@mike-marcacci , is there any common js support?
I am trying to use
fs-capacitor
in the following way and I am getting this weird error now.I am using
ts-node/ts-node-dev
for the development and here is thetsconfig.json
file.I am also using
"module": "commonjs"
inpackage.json
.The text was updated successfully, but these errors were encountered: