parcel: 🐛Uncaught Error: Cannot find module '21'
🎛 Configuration (.babelrc, package.json, cli command)
.babelrc:
{
"presets": ["env"],
"plugins": [
["babel-plugin-root-import", {
"rootPathSuffix": "js",
"rootPathPrefix": "@"
}]
]
}
package.json:
{
"name": "hwm-parcel",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "makmm",
"license": "MIT",
"dependencies": {
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-plugin-root-import": "^5.1.0"
}
}
🤔 Expected Behavior
Run $ parcel index.html, go to localhost:1234, change something in the code and the browser should get the new code and load it
😯 Current Behavior
Run $ parcel index.html, go to localhost:1234, console shows correct sourcemaps:

change something in the code and this error comes up:

Refresh, now sourcemaps are broken:

💁 Possible Solution
No idea! <.<
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.6.2 |
| Node | 9.5.0 |
| npm | 5.6.0 |
| Operating System | Debian sid |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 51 (27 by maintainers)
@DeMoorJasper Thanks, your are right. I made some tests and confirmed loading images in js is supported out of the box.
After some more tries, I found that the real cause of the “Can not find module” error is loading the same image in both HTML and JS. A minimal example to recur this error:
(assume there is a “foo.png” under the same folder:
package.json
index.html
app.js
Then
yarn && yarn devand open http://localhost:1234/index.html to see the error.(EDIT: reduced dependencies to show this is a parcel issue)
I ran into this issue today. I had JS importing the asset
import foo from "..."and later on css using the same asset as a bg imageurl(....). I tried removing .cache and renaming the asset, but it didn’t work. I had to duplicate it with a different name so JS imports one, and css the other. Can I help to get it fixed? 🔥🐛😡 😠 😡
I don’t know what HMR is. >.<
I’ve seen this error message tons of times: #198 #326 #666 #497
From looking at the issues the bugs seem totally unrelated, but I suppose maybe we should figure out where that error message is coming from and make it more informative. Or maybe the issues are actually even caused by some common bug… not sure 🤷♂️
I’ve expanded the basic html integration test to demonstrate the bug and am working on debugging it now. Any collaboration or ideas welcome.
@DeMoorJasper https://github.com/makmm/test-repo
@DeMoorJasper : It seems parcel won’t resolve the module correctly if it’s been referenced in a non-JS file previously.
I don’t know if this helps or not, but I found a workaround, which might be a hint into solving the issue.
Not working
Working
Hope this helps!
If someone else encounters this, same thing happens if you have the same image in the index.html and also imported from your JS.
The underlying error is ~the connection of
babel-polyfilland~ a javascript error:Any javascript error will cause (on the 2nd edit of the js file):
<link>below)This works:
This doesn’t work:
Minimal (non-)working example
index.html:
index.js:
index.css:
Debugging
EDIT: ~
import "regenerator-runtime/runtime"causes the same issue as “babel-polyfill”.~EDIT 2: Has nothing to do with babel-polyfill.
Commenting out the css files, this is the error on HMR reload:
@davidnagli Tried with
9.6.1, npm scripts (npm run dev) AND global (parcel index.html) and still same issue, got the number29with npm scripts tho.@davidnagli 1. not Angular 2. yes, the error is normal, I want to fix it but can’t because of this issue
It will be good if we provide file file mapping moduleId => moduleName