question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESM file extension

See original GitHub issue
internal/modules/cjs/loader.js:1015
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/proj/node_modules/quick-lru/index.js
require() of ES modules is not supported.
require() of /path/to/proj/node_modules/quick-lru/index.js from /path/to/proj/dist/src/ih-user/ih-user.guard.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.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /path/to/proj/node_modules/quick-lru/package.json.

like this?

{
  "main": "index.cjs.js",
  "module": "index.esm.js"
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Dilukacommented, Jan 19, 2021

I tried, and give up. There are some file extension naming issue with typescript in nodejs. It is not easy to change a nest.js project from commonjs to esm.

end up here:

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/to/proj/dist/src/bootstrap.module' imported from /path/to/proj/dist/src/main.js
    at finalizeResolution (internal/modules/esm/resolve.js:271:11)
    at moduleResolve (internal/modules/esm/resolve.js:694:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)
    at Loader.resolve (internal/modules/esm/loader.js:100:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
    at link (internal/modules/esm/module_job.js:46:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

3reactions
KODerFunkcommented, Apr 22, 2021

@sindresorhus Real problems with ts-node setup.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESM File Extension - What is an .esm file and how do I open it?
An ESM file is a game data file used by select Bethesda Softworks video games, such as The Elder Scrolls IV: Oblivion, The...
Read more >
What is it? How to open an ESM file? - FILExt
An ESM file contains data used by Bethesda video games such as those in the Elder Scrolls and Fallout series. It contains records,...
Read more >
How To Open File With ESM Extension?
ESM is a file extension commonly associated with Elder Scrolls Master Format files. Elder Scrolls Master Format specification was created by Bethesda ...
Read more >
File extension ESM - Simple tips how to open the ESM file.
ESM document file contains game data for Elder Scrolls 4 and 5 (named Oblivion and Skyrim, respectively). ESM files shold key game data...
Read more >
ESM File - What is it and how do I open it?
An .ESM file is an Enhanced Simplex Bitmap file. We have not yet analyzed in detail what these files contain and what they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found