parcel: Dynamic import doesn't work?
when i try code splitting, get a error:
Uncaught Error: Cannot find module '7'
index.js:
import('./m').then(fn => {
console.log(fn(1,2));
});
m.js:
export default (a, b) => a + b;
no more config…
Software | Version(s) |
---|---|
Parcel | 1.0.3 |
Node | 9.2.0 |
npm/Yarn | npm |
Operating System | macOS 10.12.6 |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 30
- Comments: 46 (11 by maintainers)
Commits related to this issue
- Fix dynamic imports exports Fixes #112 — committed to fathyb/parcel by deleted user 7 years ago
- Fix dynamic imports exports Fixes #112 — committed to fathyb/parcel by deleted user 7 years ago
- [EuiIcon]: * Add appendIconComponentCache function to complement the recently-added clearIconComponentCache function. Use case is to work around issues with the dynamic loading: if an icon is not in... — committed to wonderscore/eui by dannya 4 years ago
- [EuiIcon]: Add appendIconComponentCache function (#3481) * [EuiIcon]: * Add appendIconComponentCache function to complement the recently-added clearIconComponentCache function. Use case is to w... — committed to elastic/eui by dannya 4 years ago
almost one year and this still hasnt been fixed lmao
I doubt this issue is completely fixed. Even on parcel v2 (using v2.3.2).
Here is my error message.
I have a peice of code doing something like this. Esentially, it’s importing a model file that has a mongoose schema defined depending on the type of request.
But when I import all my models beforehand at the top of the file. It works just as expected.
This leads me to believe dynamic imports are still not fixed 100%. Please correct me if I’m wrong. The app also works fine when I use babel
nodemon --exec babel-node server.js;
Any resolution as of yet? 1.9.1 still has issues with dynamic imports (for react-loadable)
Minimal reproducible example is here. It starts happening when I include CSS file in index.html and have dynamic imports in my root JS file.
Sorry. I forgot to share my experience. I approached it in the same way as the above reproductions. I solved the problem in a temporary way as follows.
“This error occurs only with asynchronously imported static files, Create a central path management js file that has all of your static file paths.Never asynchronously import manager files that have all those path information, but manage to access them through those manager files when writing static files.”
@devongovett yes, confirmed in my case
but also I’m not able to import an svg file it says something like
I just tried below code. Works without any issue.
Hey guys, getting sort of the same problem, the built passes, but I get the following error on the web console:
Uncaught Error: Cannot find module 'Loader.844c947a.js,7,Loader.844c947a.map,7' at newRequire (loader.1eaab585.js:39)
Using:
"react-loadable": "5.4.0"
"babel-plugin-syntax-dynamic-import": "6.18.0",
"parcel-bundler": "^1.8.1"
Maybe I should name my imports with
react-loadable
somehow? or change mybabel-plugin
Code
@ranfdev my parcel version is 1.8.1 on mac pro,it works as you say that remove the css file.
Interesting +1 👍
I’m not sure if Parcel has (haven’t gotten through entire codebase yet) support for what webpack call’s ContextModules. I’m happy to help team understand how it works if they want to RFC/Propose implementing it.
@hmmhmmhm it would be more helpful if you included a reproduction step, detailed errors, etc. Otherwise you might as well add an emoji to the issue description to vote for the issue.
still no fiix about this error? It’s almost 2020 year and I’m going through this error again today.
I’ve also faced this bug. Looks like it happens when you try to import the same static file in 2 dynamically loaded modules. The asset is added to dependencies only for the first module. So, if you skip loading of the first module and just load the second one then you get this error. Here is my example: https://github.com/ArtemZag/parcel-dynamic-import-bug There are 2 scripts: “yarn try-ok” & “yarn try-bug”
Bug (at least in @dantesolis case) appears to be related to the async imported module also being included in the bundle synchronously. There is both
import Loader from './components/Loader/Loader';
andimport('./components/Loader/Loader')
in the example. If you remove the sync import it works. Does this match up with other people’s issues?The problem is even worse in the latest version (1.8.1). I can build my app using 1.7.1, but with 1.8.1 i get the error
Cannot find module '16'
. This time i don’t have any css file. I don’t know how to reproduce this, i’m not doing anything strange, it’s just a normal app using code splitting. I’m building with the cache disabledI get the same error, but only when i’m building. When i run
parcel index.html
everything works, but if i runparcel build index.html
i get that error message in some of the splitted chunks. I’m using parcel 1.6.2 on elementary os (based on ubuntu). Interesting: by removing the imports related to css files in the chunks, it works.