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

Dynamic import does not work after 2.0.7 #291

Closed
jackysee opened this issue Dec 18, 2017 · 10 comments
Closed

Dynamic import does not work after 2.0.7 #291

jackysee opened this issue Dec 18, 2017 · 10 comments

Comments

@jackysee
Copy link

I'm submitting a bug report

Webpack version:
3.10.0

Webpack Karma version:
2.0.7

Karma version:
1.7.1

Please tell us about your environment:
Windows 10

Browser: Chrome

Current behavior:
Having the webpack do the code splitting at dynamic import statement e.g. import('./file.js'), karma serve the path as system file path and chrome report that it cannot load the resource:

Not allowed to load local resource: file:///C:/Users/jackysee/AppData/Local/Temp/_karma_webpack_/0.bundle.js

Expected/desired behavior:
It should load the resource at e.g. http://localhost:9867/_karma_webpack/0.bundle.js, just as it did in version karma-webpack 2.0.6.

  • demo

https://github.com/jackysee/karam-webpack-test

@ldrick
Copy link

ldrick commented Dec 18, 2017

I've got the same problem on a Ubuntu 17.10 with ChromeHeadless and a Windows with ChromeHeadless.

Had to go back to 2.0.7, because 2.0.8 didn't work either.
Seems this 0616dda somehow broke dynamic imports.

Edit: Same as #289

@rogeriochaves
Copy link
Contributor

+1, same problem here, on phantomjs macosx and phantomjs on jenkins (some linux distro)

@rodmax
Copy link
Contributor

rodmax commented Dec 20, 2017

i hope i fixed this in # 292 #293
Please check if this is a valid solution.

@rodmax
Copy link
Contributor

rodmax commented Dec 21, 2017

@jackysee i tested https://github.com/jackysee/karam-webpack-test with #293 pull-request
It fixed this bug on my OS(Ubuntu). and i believe on MACs too

But i can't check it on Windows.
Could you(or somebody else:) ) verify it on Windows, because I have doubts
that the bug may remain on Windows due to the temp folder is a more complicated string than in Unix.

below steps may help you to quick setup env

git clone [email protected]:rodmax/karma-webpack.git
cd karma-webpack
git checkout fix-url-regex-for-custom-file-handler
npm i 
npm i [email protected]   # you should install peer dependency for using "npm link"
npm link
npm run build  # after it you should see "js" files in ./lib dir

cd path/to/karam-webpack-test
npm link karma-webpack  # mount my pull-requested version
npm run tests

@jackysee
Copy link
Author

Tested, doesn't work on windows.
Console shows Not allowed to load local resource: file:///C:/Users/jackys/AppData/Local/Temp/_karma_webpack_/0.bundle.js

image

@rodmax
Copy link
Contributor

rodmax commented Dec 22, 2017

@jackysee
thanks for quick reply, as i expected, my fix working only for unix systems,

For Windows needed more complex fix due to os.tmpdir() on Windows returns absolute path (C:/.... or something else) and browser attempts to load local file instead of request to localhost:XXX, and this request not accepted karma server at all

@sjd78
Copy link

sjd78 commented Jan 10, 2018

If it helps, the karma-webpack generated chunk asset files don't actually live on disk. They live in memory via webpack-dev-middleware. When I do something like this:

require.ensure([], (require) => {
   require('module1')
   require('module2')
   require('module3')
}, 'named-chunk')

the karma-webpack setup will generate 0.bundle.js as the asset for chunk named-chunk with those modules embedded to be lazy loaded when/if needed. Then my test code won't ever be able to load 0.bundle.js because it's looking for it on disk, and it's not there. But it is accessible on the webpack-dev-server at http://0.0.0.0:9876/_karma_webpack_/0.bundle.js.

It does work on 2.0.6.

@johnnyreilly
Copy link

Thanks so much for reporting this! I've switch back to 2.0.6 for now - my tests pass once more 👍 (Windows again)

@johman10
Copy link

I can confirm that #293 fixes the issue on Mac in more instances. Would be great if we can get this fixed soon-ish so that we can update.

I can also confirm that downgrading to 2.0.6 actually works to fix this as well, it's not perfect but it's something.

@michael-ciniawsky
Copy link
Contributor

Fix released in v2.0.10 🎉 Please try it out. If still regressions please open a new issue :)

@michael-ciniawsky michael-ciniawsky removed this from the 2.0.10 milestone Feb 25, 2018
gerrit-ovirt-org pushed a commit to oVirt/ovirt-engine-dashboard that referenced this issue Mar 13, 2018
The karma-webpack package was locked to 2.0.6 due to
issue [1].  This has been resolved in the package and
we can now use latest.

[1] - codymikol/karma-webpack#291

Change-Id: I2c72129c5428bb3106a118397d0090df1e38f867
Signed-off-by: Scott J Dickerson <[email protected]>
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

8 participants