extract-loader: SyntaxError: Unexpected token export
Using the example with Node v8.15.0 produces the error SyntaxError: Unexpected token export
at node_modules/extract-loader/lib/extractLoader.js:81:28.
The line 81 is trying to parse the source:
module.exports = "<!DOCTYPE html>\n<html>\n <head>\n <link rel=\"style\" href=\"" + require("./index.css") + "\">\n </head>\n <body>\n <img src=\"" + require("./images/desk.svg") + "\">\n <script src=\"index.js\"></script>\n </body>\n</html>";
export default __webpack_public_path__ + "c58ff9d72352b98461e9b50bc7a28553.svg";
exports = module.exports = require("../node_modules/css-loader/dist/runtime/api.js")(true);
// Module
exports.push([module.id, "body {\n font-size: 1em;\n}", "",{"version":3,"sources":["index.css"],"names":[],"mappings":"AAAA;IACI,cAAc;AAClB","file":"index.css","sourcesContent":["body {\n font-size: 1em;\n}"]}]);
export default __webpack_public_path__ + "01f1344ea069d644fc25b1b869447810.css";
Here is the full stack:
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
[snip]/src/images/desk.svg:1
export default __webpack_public_path__ + "c58ff9d72352b98461e9b50bc7a28553.svg";
^^^^^^
SyntaxError: Unexpected token export
at [snip]/node_modules/extract-loader/lib/extractLoader.js:81:28
at Generator.next (<anonymous>)
at step ([snip]/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at [snip]/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at new Promise (<anonymous>)
at new F ([snip]/node_modules/core-js/library/modules/_export.js:36:28)
at [snip]/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
at evalModule ([snip]/node_modules/extract-loader/lib/extractLoader.js:150:63)
at [snip]/node_modules/extract-loader/lib/extractLoader.js:138:28
at Generator.next (<anonymous>)
at step ([snip]/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at [snip]/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
@ multi ./src/index.js ./src/index.html main[1]
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 29 (2 by maintainers)
Commits related to this issue
- Added post about https://github.com/peerigon/extract-loader/issues/67#issuecomment-590471614 — committed to carsonreinke/reinke.co by carsonreinke 4 years ago
I bumped into this issue too. Looking at the file-loader changelog for v 5.0.0 here I read they’ve switched to ES modules by default. To restore the pre-version-5 behaviour now we need to explicitly disable the ES modules, by setting
esModule: falseinto the file-loader’s options. I just wonder how it’s working fine for themThanks for reporting ❤️. We’re working on this (and other) issues.
I believe it’s related to file-loader also.
I’ve encountered the same issue with file-loader of version 5.2.0, so I rolled back to version 4.3.0 and it works like a charm, still didn’t try [5.0.0, 5.1.0], so not sure which version starts causing a problem.
@LZQCN are you suggesting instead of Babel just using this regex? Is it that simple?
@thequailman I was able to get it to work and created this example: https://github.com/carsonreinke/extract-loader-67
@kevincox yes, @cybercase was kind enough to put in a PR #69
Are there any plans to support es modules in the extract-loader?