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
It would be great to update package.json to use exports.
Modern node understands ES modules but doesn't understand the module field of package.json (as used by bundlers etc) so gives an error on import.
We hit this using tests written with Vitest but it reproduces in trivial Node project with "type": "module" set in package.json and any named import from dapjs.
The fix that Node suggests does work, but unfortunately I can't make TypeScript happy with that approach in my real project.
➜ daptest node index.js
file:///Users/mth/Development/microbit/daptest/index.js:1
import { CortexM } from "dapjs";
^^^^^^^
SyntaxError: Named export'CortexM' not found. The requested module 'dapjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'dapjs';
const { CortexM } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:180:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:263:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)
Node.js v22.13.1
The text was updated successfully, but these errors were encountered:
It would be great to update package.json to use exports.
Modern node understands ES modules but doesn't understand the module field of package.json (as used by bundlers etc) so gives an error on import.
We hit this using tests written with Vitest but it reproduces in trivial Node project with
"type": "module"
set in package.json and any namedimport
from dapjs.The fix that Node suggests does work, but unfortunately I can't make TypeScript happy with that approach in my real project.
The text was updated successfully, but these errors were encountered: