Closed abdonrd closed 5 years ago
Seems to be an issue with the bundler when there are multiple import()
statements for the same fragment. Filed https://github.com/Polymer/tools/issues/568
It does seem that multiple dynamic imports are really kinda bad. For anyone else struggling with doing something like this:
case 'view1':
import('../components/my-view1.js').then((module) => {
import('../components/my-view2.js');
});
break;
where my-view2 is not imported in any other place (e.g. you want to create a container-page my-view1 which imports my-view2. My-view1 might include a global navigation and my-view2 is the content for a page, hence you dont need it at any other place, but you want to make sure that my-view1 is loaded before my-view2), then you will probably also get an error. But this error is unrelated to the error above. If you try to dynamically import my-view2 you also have to add fragments to your polymer.json, like so:
"fragments": [
"src/components/my-view1.js",
"src/components/my-view2.js"
]
Again: This error is unrelated. As you "hide" your components from the bundler inside the then block. You could also encounter this problem when using variables inside your imports.
To stress the point: Above error only happens when the same file is imported twice. Which may also be bad in general (why would you have 2 same dynamic imports in the first place?). If you have something that needs to be imported more than once then it might be a static import INSIDE of one or more dynamically loaded files.
When I edit:
https://github.com/Polymer/pwa-starter-kit/blob/b50a93748677c8be0bdcdc5ed71a03747628fc57/src/actions/app.js#L31-L36
To:
The website works with
npm start
. But it doesn't work withnpm run build:static && npm run serve:static
: