Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import() does not work #316

Closed
philipahlberg opened this issue Mar 12, 2018 · 6 comments
Closed

import() does not work #316

philipahlberg opened this issue Mar 12, 2018 · 6 comments

Comments

@philipahlberg
Copy link

I'm submitting a bug report

Webpack version:
4.1.1

Webpack Karma version:
2.0.13

Karma version:
2.0.0

Please tell us about your environment:
Windows 10

Browser: [Chrome 64] (probably others as well)

Current behavior:
import() fails with the error:
Error: Loading chunk 0 failed.

Expected/desired behavior:
import() should import a script and the exports should be available.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.
    See https://github.com/philipahlberg/karma-webpack-dynamic-import for a setup that showcases the problem.
    The minimum necessary steps to reproduce is:
npm install --save-dev karma webpack karma-webpack
  1. setup a test that uses import()
  2. execute the test
  • What is the expected behavior?
    import('./import.js') should import the file './import.js' and return its exports.

  • What is the motivation / use case for changing the behavior?
    To allow testing things with dynamic imports.

@philipahlberg philipahlberg changed the title import() does not load the relevant chunk import() does not work Mar 12, 2018
@jamesopti
Copy link

jamesopti commented Mar 21, 2018

Im seeing this issue as well but when using Webpack4's optimization.splitChunks to split out my vendor bundle.

Webpack version:
4.1.1

Webpack Karma version:
3.0.0

Karma version:
1.7.0

Please tell us about your environment:
Mac OSX Sierra 10.12.6

Browser: [Chrome 57]

Current behavior:
Vendor chunk fails to load

Expected/desired behavior:
vendor chunk should be available at http://localhost:9876/_karma_webpack_/vendor.js

Webpack Config:

optimization: {
  splitChunks: {
      cacheGroups: {
        vendor: {
          test: /\/node_modules\//,
          name: 'vendor',
          chunks: 'initial',
          filename: '[name].js',
        },
      },
    },
}

Custom Context File

...
  <script src="context.js"></script>
  <script src="debug.js"></script>
  <script type="text/javascript">
    // Configure our Karma
    %CLIENT_CONFIG%
    // All served files with the latest timestamps
    %MAPPINGS%
  </script>
  <!-- Dynamically replaced with <script> tags -->
  <script type="text/javascript" src="_karma_webpack_/vendor.js" crossorigin="anonymous"></script>
  <script type="text/javascript" src="_karma_webpack_/firstparty.js" crossorigin="anonymous"></script>
  %SCRIPTS%
  <script type="text/javascript">
    console.log('Using custom debug file test.customDebugFile.html');
    window.__karma__.loaded();
  </script>
...

@philipahlberg
Copy link
Author

FWIW, it's also broken for karma-webpack 4.0.0-beta.0 + webpack 4.1.1.

@jamesopti
Copy link

+1 - This seems to be a regression that's happened multiple times now in a world where code splitting and dynamic imports are only getting more prevalent.

@ggriffithsIDBS
Copy link

+1 seeing this in latest version with Webpack 3
Error: Loading chunk 0 failed

@tingc10
Copy link

tingc10 commented Nov 26, 2018

Not sure if this is the same error, but I solved this by setting webpack's output.chunkFilename and output.filename to [name].js. I noticed the chunk was being named to 1-undefined.js.

@matthieu-foucault
Copy link
Collaborator

The dynamic import bug on Windows (also reported in #362 ) was fixed in #373. installing karma-webpack@next would fix it

philippfromme added a commit to camunda/camunda-modeler that referenced this issue Apr 25, 2019
merge-me bot pushed a commit to camunda/camunda-modeler that referenced this issue Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants