Missing esm build file
barraponto opened this issue · 4 comments
Using 3.0.3 I see an error with import random from "random" in a Create React App project.
It says:
./node_modules/random/dist/esm/index.js
Module not found: Can't resolve './random' in './node_modules/random/dist/esm'
I've double checked: there is an index.js there, it tries to require('./random').default but fails because there isn't any random.js file in there :(
I believe it might be connected to #19
Greetings of the day @transitive-bullshit
I'm still facing this issue. I installed random, still, it doesn't get imported in the react application. Here are the screenshots explaining the same issue
Looking forward to hearing from you
Regards
Sam Varghese
Hi @Sam-Varghese! Thanks for reporting this. I was able to replicate the issue when using webpack 5. I think it may be related to webpack/webpack#11467. Are you using webpack 5?
It appears that the fix provided by #35 does not assist us here. I will investigate a further amendment to how this package is built. I have struggled a bit to get the ts -> js
build process to work for all desired targets.
@Sam-Varghese I have narrowed this down a bit. As this is an ESM module "type": "module", imports are resolved in a very strict fashion. I have identified two fixes:
- Provide the file extension
.js
in the relative import paths of therandom
library code. This allows webpack 5 to resolve the files correctly. - Remove
"type": "module"
.
Option 1 seems cumbersome. I imagine there is a more elegant solution. Perhaps with the package.json
exports
or browser
fields. Option 2 seems like a step backward. I will mull this over and make a PR soon.
Ok, thanks @agmoss for working on this issue, and providing me with fixes so soon! Really appreciate your efforts 🎉