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 error with ES6 js script embedded in html body #270

Closed
benjaminpreiss opened this issue Mar 27, 2020 · 4 comments
Closed

Import error with ES6 js script embedded in html body #270

benjaminpreiss opened this issue Mar 27, 2020 · 4 comments

Comments

@benjaminpreiss
Copy link

benjaminpreiss commented Mar 27, 2020

  • Operating System: Windows 10 Pro
  • Node Version: 13.12.0
  • NPM Version: 6.14.4
  • webpack Version: 4.42.1
  • html-loader Version: 1.0.0

Expected Behavior

html-loader should process index.html and pass the embedded ES6 js script to babel loader.

Actual Behavior

Running npx webpack resp. npm run webpack returns this error:

ERROR in ./src/html/index.html
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
C:\ ... \website\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import { gsap } from 'gsap';
                                                              ^^^^^^

SyntaxError: Cannot use import statement outside a module
...

Code

webpack.config.js and package.json

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    ...
</head>
<body id="#body">
    <script type="module" src="../index.js"></script>
</body>
</html>

index.js:

import { gsap } from 'gsap';
import fullpage from 'fullpage.js';
import $ from 'jquery';

var ...

How Do We Reproduce?

File structure:

 - src/
         - html/
                - index.html
         - index.js

 - dist/
 - webpack.config.js
 - package.json

Then run npm run webpack

@alexander-akait
Copy link
Member

Please create full reproducible test repo

@alexander-akait
Copy link
Member

Looks extract-loader is broken

@alexander-akait
Copy link
Member

Yes, broken extract-loader, please open an issue in extract-loader repo, we can't fix it on our side, sorry

@cecilia-sanare
Copy link

For those who find this issue, here's a link to the related issue on extract-loader.

peerigon/extract-loader#79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants