Receiving uncompiled source (import/export) with Webpack 2 (inject-loader 2.0.0 / 3.x)
See original GitHub issueI used inject-loader with webpack 1.x and it functioned perfectly. Porting the code to webpack 2 gives some funny errors.
If I change the code to use require("inject-loader!...
I get errors like so:
ERROR in ./~/inject-loader/lib!./source/ccc/CCCProxy.js
Module parse failed: /home/user/work/my-project/node_modules/inject-loader/lib/index.js!/home/user/work/my-project/node_modules/babel-loader/lib/index.js!/home/user/work/my-project/source/ccc/CCCProxy.js 'import' and 'export' may only appear at the top level (30:0)
You may need an appropriate loader to handle this file type.
| * @created 2015-08-25
| */
| import CustomObject from "core/CustomObject";
| import CCCResponse from "ccc/CCCResponse";
| import CCCManagerLocator from "misc/locators/CCCManagerLocator";
@ ./test/specs/ccc/CCCProxy.spec.js 27:29-66
@ ./test \.spec\.js$
@ ./test/index.js
If I leave it as "inject!...
, I get other errors:
ERROR in ./test/specs/ccc/CCCProxy.spec.js
Module not found: Error: Can't resolve 'inject' in '/home/user/work/my-project/test/specs/ccc'
@ ./test/specs/ccc/CCCProxy.spec.js 27:29-59
@ ./test \.spec\.js$
@ ./test/index.js
I’m using Node 6.8 with Webpack 2.1.0-beta.26. I’ve tried inject-loader 2.0.1 and v3 beta. My code is es6 using import/export being transpiled with babel 6. All code is transpiled correctly to commonjs format which I can confirm by checking the output.
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (6 by maintainers)
Top Results From Across the Web
imports-loader - webpack
Be careful, existing imports ( import / require ) in the original code and importing new values can cause failure. Getting Started. To...
Read more >Failed to use yaml lib with webpack 5 · Issue #208 - GitHub
js 1:0 Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0) You may need an appropriate loader to handle ......
Read more >Getting error with webpack when using import/export
For webpack to be able to resolve typescript file, you need to add it to the list of webpack extensions. By default, webpack...
Read more >eslint-plugin-import - npm
This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import ...
Read more >Webpack and bundlers · Bootstrap v5.0
Learn how to include Bootstrap in your project using Webpack or other bundlers. On this page. Installing Bootstrap; Importing JavaScript; Importing Styles.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s because it isn’t converting the modules.
What I settled on was running the tests under a different environment.
Then setting
process.env.NODE_ENV = "test";
inside the karma.conf.js file. You could also set theNODE_ENV
environment variable on the command line if you wished.@perry-mitchell Awesome—thanks! Nah, it’s OK, I’ll package it up. Will make sure I credit you though 👍