-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New error with 8.0.0? Error [ERR_REQUIRE_ESM]: require() of ES Module - How to resolve? #301
Comments
This feels like a tsconfig problem? My tsconfig.json file is {
"compilerOptions": {
"target": "es2022",
"module": "commonjs",
"lib": [
"es2022"
],
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"esModuleInterop": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/@types"
]
},
"exclude": [
"node_modules",
"dist"
]
}
and the generated .js file includes Object.defineProperty(exports, "__esModule", { value: true });
const chai = __importStar(require("chai"));
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
const instrumentedResource_1 = require("../../drivers/instrumentedResource");
const driverInterface_1 = require("../../drivers/driverInterface");
chai.use(chai_as_promised_1.default); |
you're in a commonjs project ( 8.0.0 is esm-only (like chai 5.x is too) so you can either:
|
Thanks. It looks like doing that and I'll have to change 500+ imports to include explicit |
Node will probably still handle the imports without extensions but I guess typescript may complain if they're not exported paths 😬 It should be scriptable at least but I understand your pain (code review won't be a fun one) You may be able to loosen typescript's constraints by using |
The problem is you can't use 8.0.0 with Typescript yet, because the import * as chaiAsPromised from "chai-as-promised";
use((chaiAsPromised as any).default); Once the import chaiAsPromised from "chai-as-promised";
use(chaiAsPromised); |
we should definitely push a new major to the if anyone has time to contribute that upstream to DT, i'd be happy to review |
But the quoted
driverInterface.spec.js
is built from a TS which is:Which bit of the code is wrong? (sorry, I'm maintaining a project, but didn't set up any of this TS/JS stuff)
The text was updated successfully, but these errors were encountered: