-
Notifications
You must be signed in to change notification settings - Fork 74
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
SyntaxError: Unexpected token export #67
Comments
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. |
@stassribnyi correct sir, downgrading fixed the issue. When I look at the source being provided, it is ES5 instead of ES6. I believe an adjustment to this project could help too.
|
Looking at solving this. The issue is simple VM (just like CLI) for Node will not interpret ES6 import/export statements. Copying and pasting the code ES6 code above will produce an error on any Node CLI versions. One solution would to have Babel transform this, since there is already an odd dependency on babel-runtime 6. Another would be to write the script to file and run it and extract the data. I like something like this better because it would potentially remove a dependency and locking people on Babel 6. |
I bumped into this issue too. |
@cybercase yes, looks like that is an option https://github.com/webpack-contrib/file-loader#esmodule. |
content.replace(/export default/g, "module.exports =") Maybe it's useful to insert this code in the right place. |
@LZQCN are you suggesting instead of Babel just using this regex? Is it that simple? |
@carsonreinke To deal with the new file-loader version, yes, it would be that simple. However, there's a past PR ( #26 ) where the maintainer already discussed a fix of this kind, and expressed the willing to use babel for proper transpilation, so I've opened a PR ( #69 ) to handle es modules using babel. |
After too many hours trying to work out why my Webpack config kept failing, I am very glad to have found this issue.
Rolling back to |
Thanks for reporting ❤️. We're working on this (and other) issues. |
Same here, unfortunately the |
@rodrigoyoshida I don't know the exact version of the |
@cybercase @rodrigoyoshida looks like definitely v5.0.2 has it fixed https://github.com/webpack-contrib/file-loader/blob/v5.0.2/src/index.js#L63 |
Still seeing this with 5.0.2, I think:
|
Are there any plans to support es modules in the extract-loader? |
@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 |
/// esModule: false, will solve your issue
|
@kamleshlikhare you don't need all the Wondering if there is a way to enable that globally... |
The
|
@scott-ln well, you can't use 4.0.3, so you probably need to tweak those dependencies to get it up to >=5.0.2. Try setting file-loader dependency to |
Isn't better doing what the val-loader does ? import Module from 'module';
function exec(code, loaderContext) {
const { resource, context } = loaderContext;
const module = new Module(resource, parentModule);
// eslint-disable-next-line no-underscore-dangle
module.paths = Module._nodeModulePaths(context);
module.filename = resource;
// eslint-disable-next-line no-underscore-dangle
module._compile(code, resource);
return module.exports;
} https://github.com/webpack-contrib/val-loader/blob/master/src/index.js#L10-L23 Or the Module would suffer from the same problem? |
Perhaps using ChildCompilation? more...
After reading the WebPack to understand what happens after the File-Loader. After it the Acorn Parser runs and produces AST for the Harmony. I think the cleanest way would be creating a child compilation targeting Node so WebPack can deal with it for us. sources: |
@Luiz-Monad I think you might be reading into a bit much, the problem is simple, Will that |
Actually I was over-complicating things. I discovered this file. I just took this file and turned it into a loader, it does exactly what I needed. I just plugged it after my html-loader, works like a charm. |
Rolling back works for me, thanks |
@carsonreinke wrote:
Sorry, I'm not sure what you mean? 4.0.3 is the latest version of extract-loader, not file-loader (which is installed at 5.0.2 in this scenario). |
@scott-ln 🤦♂️ , sorry @Luiz-Monad it sounds like this might be a better solution to using Babel, do you have anything you can share and we could possible get a PR together? |
The issue should be solved with |
@Luiz-Monad Can you elaborate a bit? It sounds like you're trying to do exactly what I'm trying to do. I was trying to harvest some code from i.e., I want the evaluated/executed version of a file. How did you convert compiler.js into a loader? |
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:
Here is the full stack:
The text was updated successfully, but these errors were encountered: