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.

bundle with esbuild fails because `yargs/yargs` does not have file extension

See original GitHub issue

Possible duplicate of #1929 but I’m not sure because that ticket is too vague.

esbuild determines content types based on file extension. esbuild docs

But yargs/yargs does not have a file extension.

This raises an error:

$ echo 'import createYargs from "yargs/yargs";' | yarn esbuild --bundle --loader=js
 > <stdin>:1:24: error: Do not know how to load path: node_modules/yargs/yargs
    1 │ import createYargs from "yargs/yargs";
      ╵                         ~~~~~~~~~~~~~

1 error

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
yoursunnycommented, Feb 14, 2022

This is becoming a fatal error with Node 17.x where the top-level project is Node.js ESM (not TypeScript).

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /home/ubuntu/app/node_modules/.pnpm/yargs@17.3.1/node_modules/yargs/yargs
    at new NodeError (node:internal/errors:371:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:84:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:99:38)
    at defaultLoad (node:internal/modules/esm/load:21:14)
    at ESMLoader.load (node:internal/modules/esm/loader:359:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:81:21)
 ```
2reactions
bcoecommented, Aug 25, 2021

Keeping this file without an extension is a hack necessary to prevent yargs from treating the file as ESM, since for the benefit of TypeScript, the package.json is of type, module.

This can be fixed as soon as TypeScript supports a .mjs extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Types - ESBuild
Modern bundlers contain an optimization called "scope hoisting" that merges all bundled files into a single file and renames variables to avoid name...
Read more >
esbuild | Yarn - Package Manager
Certain packages contain files without an extension. For example, the yargs package contains the file yargs/yargs which has no extension.
Read more >
esbuild not bundling files - javascript - Stack Overflow
I am trying to use esbuild to bundle and minify my files in an npm project. It is minimizing every file that I...
Read more >
esbuild: Versions | Openbase
So for example an extensionless file in a "type": "module" package is now treated as ... constructor call so the resulting code doesn't...
Read more >
Credits - Octopus Deploy
Package Authors and/or maintainers License @amplitude/types Amplitude Inc MIT @amplitude/ua‑parser‑js Faisal Salman MIT @amplitude/utils Amplitude Inc MIT
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