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

__dirname is not defined in ES module scope (when using commonjs dependency from es module package) #895

Closed
BCaspari opened this issue Mar 24, 2022 · 2 comments

Comments

@BCaspari
Copy link

In a project with "type": "module" in the package.json that uses the vm2 package (or any other package that uses the __dirname or __filename variables), the generated output throws an Error:

`(function(global) {"use strict"; const exports = {};${fs.readFileSync(`${__dirname}/bridge.js`, 'utf8')}\nreturn exports;})`);
                                                                                
ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'C:\ph\ProcessHub_master\app\distncc\package.json' contains "type": "module". To 
treat it as a CommonJS script, rename it to use the '.cjs' file extension.

The project runs without problems when starting with node. I think __dirname and __filename should be removed from the ncc build?

@styfle
Copy link
Member

styfle commented Apr 1, 2022

Sounds similar to #749

@styfle
Copy link
Member

styfle commented Feb 12, 2024

Closing as a duplicate of #749

@styfle styfle closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
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