Closed yasaichi closed 3 months ago
@koros @musale Any chance you can confirm if this is expecte/related to the changes at https://github.com/microsoft/kiota-typescript/pull/1102
Just to confirm @yasaichi, does this error occur with the latest versions(1.0.0-preview.53) as well?
@andrueastman Yes. Unfortunately, it also occurs in the latest version (preview.53).
In my understanding, the build output does not conform ES Modules specifications at some points, one of which is that import
and export
do not come with file extensions.
Reopening the issue it seems from the latest release 1.0.0-preview.54 the issue isn't fully fixed especially for pure javascript files in node.js environment
@yasaichi This is what I have on my end:
tsconfig.json
{
"compilerOptions": {
"target": "ESNext", // Target the latest JavaScript features
"module": "ESNext", // Use ESNext module syntax (ESM)
"moduleResolution": "node", // Node module resolution strategy
"esModuleInterop": true, // Enable interoperability between CommonJS and ESM
"skipLibCheck": true, // Skip type checking of declaration files
"strict": true, // Enable all strict type-checking options
"forceConsistentCasingInFileNames": true,
"outDir": "./dist" // Output directory for compiled files
},
"include": ["src"], // Include all files in the src directory
"exclude": ["node_modules", "dist"] // Exclude node_modules and dist directories
}
index.ts
import { parseGuidString } from "@microsoft/kiota-abstractions";
console.log(parseGuidString("3f2e8b1e-66ae-4f2d-bc8e-367f2e1b2e94"));
npm i -D tsx
npx tsx src/index.ts
It might not work for your case since you're using .js
, so maybe only option is to bring back cjs
support
@koros
Thank you for your thoughts. With your tsconfig.json
and tsx
, I could run index.ts
that you also gave. However, when it comes to the build output, it is still not working.
I don't think everyone uses tsx
or something like this to run a backend application in production, that's why we could say there is still an issue to solve, unfortunately.
// index.ts
import { parseGuidString } from "@microsoft/kiota-abstractions";
console.log(parseGuidString("3f2e8b1e-66ae-4f2d-bc8e-367f2e1b2e94"));
// ./dist/index.js (tsc output)
import { parseGuidString } from "@microsoft/kiota-abstractions";
console.log(parseGuidString("3f2e8b1e-66ae-4f2d-bc8e-367f2e1b2e94"));
$ node dist/index.js
node:internal/modules/esm/resolve:260
throw new ERR_MODULE_NOT_FOUND(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/yuichigoto/kiota-sample/node_modules/@microsoft/kiota-abstractions/dist/es/src/apiClientBuilder' imported from /Users/yuichigoto/kiota-sample/node_modules/@microsoft/kiota-abstractions/dist/es/src/index.js
at finalizeResolution (node:internal/modules/esm/resolve:260:11)
at moduleResolve (node:internal/modules/esm/resolve:920:10)
at defaultResolve (node:internal/modules/esm/resolve:1119:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:511:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///Users/yuichigoto/kiota-sample/node_modules/@microsoft/kiota-abstractions/dist/es/src/apiClientBuilder'
}
Node.js v22.2.0
I agree
@koros
I cannot imagine how hard it is, but one of the most possible solutions is to append .js
extension to all import
statements. This does not need to add an additional build tool other than tsc
.
closing since #1213 got merged. Let us know if you see further issues.
I found that there has been a package import error since
1.0.0-preview.52
ofkiota-abstractions
was released. It would be related to drop of cjs bundling. Here is the minimum code to reproduce the issue:Setup
index.js
package.json
Execution result
1.0.0-preview.51
1.0.0-preview.52 or later