Parcel: Importing the same static file inside two different dynamic imports doesn't work

Created on 27 Aug 2018  路  4Comments  路  Source: parcel-bundler/parcel

馃悰 bug report


I have a project that dynamically imports two components, inside both of those components I import the same static file.
That static file doesn't get copied to the distfolder. This also happens if you import multiple files using globs.
If I only import that file/s inside one dynamic component then it works fine.

馃帥 Configuration (.babelrc, package.json, cli command)

You can see a simplified replication here on github.

馃 Expected Behavior


All the files should be copied into the dist folder.

馃槸 Current Behavior

None of the imported files are copied.

馃拋 Possible Solution


If I knew I would have made a pull request.

馃敠 Context


Well, this makes parcel unusable for me, and its a shame since I really like it and im trying to promote it in my workplace.

馃捇 Code Sample

Minimal reproduction of the bug:
https://github.com/samuelgozi/parcel-bug-replication

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.9.1 |
| Node | 10.8.0|
| npm/Yarn | yarn 1.9.4 |
| Operating System | macOS|

Bug Confirmed Bug

Most helpful comment

For now, a workaround this issue will be to add an import for the same files in a non-dynamic JS component.
For example, add import './assets/icons/*.svg'; to the main JS file, and those files will be copied, and you will be able to use them in dynamically imported JS files as you normally would.

All 4 comments

For now, a workaround this issue will be to add an import for the same files in a non-dynamic JS component.
For example, add import './assets/icons/*.svg'; to the main JS file, and those files will be copied, and you will be able to use them in dynamically imported JS files as you normally would.

@samuelgozi can you check if this still happens with the latest version of parcel? Looks related to https://github.com/parcel-bundler/parcel/issues/2012#issuecomment-431596339 which is already solved

@victor-cordova Thanks for the update, It seems like the bug is fixed.
The issue can be closed.

I'm on 1.11.0 and having this issue. It's with all imports, including actual JavaScript imports. Same goes for #2012

As a note I'm using a React lazy load component that looks a bit like this:

import React, { lazy, Suspense } from 'react';

import Loading from '/shared/components/Loading';

function DefaultFallback() {
  return <Loading />;
}

export default (route, timeout = 800, Fallback = <DefaultFallback />) => {
  const Component = lazy(() => {
    return Promise.all([
      route,
      new Promise((resolve) => setTimeout(resolve, timeout)),
    ])
    .then(([moduleExports]) => moduleExports);
  });
  return (props) => (
    <Suspense fallback={Fallback}>
      <Component {...props} />
    </Suspense>
  );
};

Edit: I'm currently trying to recreate the bug and utterly failing to do so... but I'll keep trying!
Edit edit: It's super bonkers. I can't recreate. But an include in an include() in an include, plus perhaps react-router (but might be a red herring) and then those include() being required more than once... it seems to think something is covering for the dependency but it's not. I'll create a new issue once I have it pinned down but for now I just need to make sure I force a real include as early on as possible to ensure the dependency is loaded in into the main bundle or at an early tendril of it. Shrug emoji!

Was this page helpful?
0 / 5 - 0 ratings