Closed jedaan closed 1 year ago
Hi,
thanks for asking!
It looks to me like the error comes from: C:\ppf\yettel-auth\dist\app.js
Are you sure that this file uses import
instead of require
?
Kind regards, Hans
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
I have this same problem. Using typescript, it converts this:
const fastifyOpenApiGlue = await import('fastify-openapi-glue');
into this:
const fastifyOpenApiGlue = await Promise.resolve().then(() => __importStar(require('fastify-openapi-glue')));
Hi Matt,
The trick seems to be to prevent Typescript from converting back to commonJS. Did you see: https://github.com/seriousme/fastify-openapi-glue/issues/427 ?
If that does not resolve it can you please share your tsconfig.json ?
Kind regards, Hans
In looking at #427, it seems that part of the solution is setting type: module
in package.json
. We have a blend of TS and JS files in our package, so converting to a pure module would be a huge lift.
This is our current tsconfig:
{
"compilerOptions": {
"target": "es2017",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"rootDir": "./src",
"resolveJsonModule": true,
"allowJs": true,
"sourceMap": true,
"outDir": "./build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"./**/*",
"src/**/*.json"
],
"exclude": [
"./test/**/*",
"./build/**/*",
"./*.js",
"node_modules"
]
}
Looking at: https://2ality.com/2021/06/typescript-esm-nodejs.html you might want to set:
"module": "ES2020", // (A)
"moduleResolution": "Node", // (B)
"allowSyntheticDefaultImports": true, // (C)
Hope this helps!
Hi , i am using fastify with typescript getting the below error
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ....\node_modules\fastify-openapi-glue\index.js [App] require() of ES modules is not supported. [App] require() of....\node_modules\fastify-openapi-glue\index.js from C:\ppf\yettel-auth\dist\app.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.
my tsconfig { "extends": "fastify-tsconfig", "compilerOptions": { "outDir": "dist", "sourceMap": true }, "include": ["src/*/.ts", "src/routes/customers/schema.ts"] }