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
I'm having an issue importing this package within an ESM project running on Node.js v20. This is the error:
/workspaces/data-portal/build/node_modules/.pnpm/[email protected]/node_modules/readdir-glob/dist/esm/index.js:1
import * as fs from 'fs';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (node:internal/modules/cjs/loader:1281:20)
at Module._compile (node:internal/modules/cjs/loader:1321:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at cjsLoader (node:internal/modules/esm/translators:348:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
It appears that the dist/esm/indes.js file is being loaded as a CommonJS module rather than an ESM one. I believe the issue is that the file uses a .js extension which node.js will load as a CommonJS module because the package.json file does not contain "type": "module". To fix this the extension for the ESM's index file should be changed to .mjs so that node.js knows it's an ESM.
Interestingly when I have the same import within a TypeScript project run via tsx this error doesn't occur. I believe that tsx uses its own module loader and detects the module type by looking for ESM import/export statements rather than relying on package.json and the file extension like node.js does.
The text was updated successfully, but these errors were encountered:
Hello! Thank you for your work on this package.
I'm having an issue importing this package within an ESM project running on Node.js v20. This is the error:
It appears that the
dist/esm/indes.js
file is being loaded as a CommonJS module rather than an ESM one. I believe the issue is that the file uses a.js
extension which node.js will load as a CommonJS module because the package.json file does not contain"type": "module"
. To fix this the extension for the ESM's index file should be changed to.mjs
so that node.js knows it's an ESM.Interestingly when I have the same import within a TypeScript project run via
tsx
this error doesn't occur. I believe thattsx
uses its own module loader and detects the module type by looking for ESM import/export statements rather than relying on package.json and the file extension like node.js does.The text was updated successfully, but these errors were encountered: