question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Receiving uncompiled source (import/export) with Webpack 2 (inject-loader 2.0.0 / 3.x)

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rmp135commented, Dec 5, 2016

That’s because it isn’t converting the modules.

What I settled on was running the tests under a different environment.

{
    "env": {
        "test": {
            "presets": [
                ["es2015"]
            ]
        }
    },
    "presets": [
        ["es2015", { "modules": false }]
    ]
}

Then setting process.env.NODE_ENV = "test"; inside the karma.conf.js file. You could also set the NODE_ENV environment variable on the command line if you wished.

1reaction
plasticinecommented, Dec 4, 2016

@perry-mitchell Awesome—thanks! Nah, it’s OK, I’ll package it up. Will make sure I credit you though 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found