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

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module #199

Closed
kutny opened this issue Apr 5, 2023 · 1 comment
Closed

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module #199

kutny opened this issue Apr 5, 2023 · 1 comment

Comments

@kutny
Copy link

kutny commented Apr 5, 2023

Hi, I'm kind of a typescript beginner also coming from the PHP/Symfony world.

Got the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/jirka/projects/page-scraper/src/openai/ClientFactory.ts
require() of ES modules is not supported.
require() of /home/jirka/projects/page-scraper/src/openai/ClientFactory.ts from /home/jirka/projects/page-scraper/node_modules/node-dependency-injection/dist/lib/Loader/FileLoader.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 /home/jirka/projects/page-scraper/package.json.

I have "type": "module" set in package.json

My tsconfig.json

{
  // source https://github.com/wclr/ts-node-dev/issues/314
  "ts-node": {
    "transpileOnly": true,
    "esm": true,
  },
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "rootDir": "src",
    "strict": true,
    "sourceMap": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

services.yaml

services:

  test_service:
    class: "./openai/ClientFactory"
    arguments:
      - "some_key"

Typescript: 5.0.3

running a .ts script using nodemon --experimental-specifier-resolution=node ./src/index.ts

Thanks for your help

@zazoomauro
Copy link
Owner

This is an issue related with Ts and NodeJs . Not with ndi itself.
seems like your are not using import but require or something like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants