-
Notifications
You must be signed in to change notification settings - Fork 194
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
ReferenceError: require is not defined - when using "type": "module" in package #445
Comments
Sorry, can you create a repo for me to test on? Module system related issues are really hard to reproduce on my side. There does exist logic to try inferring the current module system here, but we might have missed some cases. |
Added section with the repo I'm trying to get this working on. I tried options.esModule = true but that messed up some other things that I think were expecting commonjs for whatever reason. |
The option does accept |
I tried the include/exclude a bit, but after a while gave up. It seemed to behavior like module: true with the 'default' options for include and exclude specified. Maybe if I could include/exclude for 'auto' and have another matcher for forcing a specific way. Otherwise I'm forced to find all the things that need one way or another. |
Based on https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/loader/utils/getModuleSystem.js it looks like maybe it's only using one packageJson globally - rather than searching upwards to find the closest packagejson based on the module's directory. |
Yes, when that was implemented it was based on a somewhat naïve assumption (for performance mainly) that I guess correctness would be better here, but it could degrade cold start performance slightly since that would mean we need to traverse all directories for all branches of the tree from |
Hmm what leads it to cover node_modules, babel is excluded in the webpack config here https://github.com/ntucker/anansi/blob/master/packages/webpack-config-anansi/src/base/index.js#L146 |
|
The way it's currently setup it doesn't build anything in /packages/ in webpack - you have to first build them to create their /lib that is used by exports - which is what the |
Yep, but since those |
Actually, while testing this I realised that there could be another way to circumvent this issue while I continue to test a new heuristic - you can specify any paths outside of the currently compiled base path to the |
I played with exclude a bit but couldn't figure it out. Not sure if it was matching correctly or anything |
Still getting this issue with:
|
Version
0.5.0-rc.1
Description
With no "type" in package.json:
Adding "type": "module"
Perhaps this is thinking "type" will also say commonjs?
You can use @rest-hooks/[email protected] as an example if you so desire.
Related
#337
https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/loader/utils/getModuleSystem.js
Extra info
I tried removing the package.json "exports" member, but that didn't change anything.
Reproducing repo
This puts require() in
packages/normalizr/lib/special.js
wherepackages/normalizr/package.json
has"type": "module",
The text was updated successfully, but these errors were encountered: