Skip to content
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

Getting nestia SDK/swagger to work with ESM? #566

Closed
li-dennis opened this issue Aug 28, 2023 · 2 comments
Closed

Getting nestia SDK/swagger to work with ESM? #566

li-dennis opened this issue Aug 28, 2023 · 2 comments
Assignees
Labels
invalid This doesn't seem right question Further information is requested

Comments

@li-dennis
Copy link

li-dennis commented Aug 28, 2023

Question

I'm playing around with nestia, and really like it so far, it looks like it'll solve a lot of our pain points around using DTOs and generating a client API. I'm trying to get the SDK to play nice with ESM, but I seem to be running into issues around import() and require(). Is it ESM compatible?

My tsconfig uses

{
    "compilerOptions": {
        "module": "ES2022",
        "target": "ES2020",
        "moduleResolution": "node",
...
}
$ npx nestia sdk "src/**/*.controller.ts" --out ./nestia_api
-----------------------------------------------------------
 Nestia SDK Generator
-----------------------------------------------------------
Analyzing reflections
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Error on ".../src/agents/agents.controller.ts" file. Check your code.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .../src/agents/agents.controller.ts
require() of ES modules is not supported.
require() of .../src/agents/agents.controller.ts from .../node_modules/@nestia/sdk/lib/analyses/ReflectAnalyzer.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from .../package.json.

    at createErrRequireEsm (.../node_modules/ts-node/dist-raw/node-internal-errors.js:46:15)
    at assertScriptCanLoadAsCJSImpl (.../node_modules/ts-node/dist-raw/node-internal-modules-cjs-loader.js:584:11)
    at Object.require.extensions.<computed> [as .ts] (.../node_modules/ts-node/src/index.ts:1610:5)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at .../node_modules/@nestia/sdk/src/analyses/ReflectAnalyzer.ts:22:41 {
  code: 'ERR_REQUIRE_ESM'
}
@acchou
Copy link

acchou commented Aug 28, 2023

This might be fixed by changing "module" to "node16" in tsconfig.json. See nightwatchjs/nightwatch#3858 (review)

@samchon
Copy link
Owner

samchon commented Sep 10, 2023

Use CommonJS. No way to support ESM, especially when below feature comes

microsoft/TypeScript#54276

@samchon samchon closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2023
@samchon samchon self-assigned this Sep 10, 2023
@samchon samchon added invalid This doesn't seem right question Further information is requested labels Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants