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] with ts-node #12

Closed
echoja opened this issue Apr 14, 2021 · 1 comment
Closed

Error [ERR_REQUIRE_ESM] with ts-node #12

echoja opened this issue Apr 14, 2021 · 1 comment

Comments

@echoja
Copy link

echoja commented Apr 14, 2021

Error occured when I execute ts-node with file-url@4.0.0 as below:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/taehoon/Desktop/cinesopa-webapp/server/node_modules/file-url/index.js
require() of ES modules is not supported.
require() of /home/taehoon/Desktop/cinesopa-webapp/server/node_modules/file-url/index.js from /home/taehoon/Desktop/cinesopa-webapp/server/src/manager/file.ts 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.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/taehoon/Desktop/cinesopa-webapp/server/node_modules/file-url/package.json.

And this is my tsconfig.json.

{
  "compilerOptions": {
    "incremental": true,
    "checkJs": true,
    "baseUrl": ".",
    "module": "CommonJS",
    "target": "ES2020",
    "moduleResolution": "node",
    "sourceMap": true,
    "paths": {
      "@/*": ["src/*"],
      "@config/*": ["config/*"]
    },
    "outDir": "ts-build",
    "diagnostics": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
  },
  "include": ["src/**/*", "config/**/*", "test/**/*"],
  "exclude": ["node_modules", "**/node_modules/*"]
}

and what I executed command is:

NODE_ENV=development ts-node-dev --transpile-only --respawn -r tsconfig-paths/register --watch ./src/**/*.pug,./src/**/*.graphql --trace-warnings --trace-uncaught -- ./src/index.js

When I was trying to test with mocha, something went wrong as well. So I guess other packages or my settings made no problems...
I don't have any error where it is file-url@3.0.0.

@sindresorhus
Copy link
Owner

Please read the release notes.

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