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.

[Bug] shipped `.mjs` bundle includes reference to `__dirname`

See original GitHub issue

__dirname is not available in ES modules. Had to switch my project to ESM for another dependency and this came up as an error. I’m not clear on how files are handled, but maybe it’s not respecting the

"exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.cjs"
    },
    "./*": "./*"
  },

from the package.json of auto-imported modules

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
userquincommented, Nov 23, 2021

Oh, yep. Sorry about that.

Issue created on vite-plugin-inspect

1reaction
josh-hemphillcommented, Nov 23, 2021

I had to uninstall and reinstall. Now it works. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - __dirname is not defined in Node 14 version
According to this issue, the problem arises if you load it as an ECMAScript module which do not contain __dirname.
Read more >
ESM builds should substitute `__filename` and `__dirname ...
When building an ESM build in Webpack, free __filename and __dirname references in CommonJS files should be supported. What is motivation or use...
Read more >
Publish ESM and CJS in a single package - Anthony Fu
A short tutorial of shipping both ESM and CJS dual formats in a single NPM package.
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Introduction#. ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and ......
Read more >
What does it take to support Node.js ESM? – The Guild
For the reason just mentioned, the standard package.json#exports should look ... like filedirname that does a trick inspecting error stacks, ...
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