Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
fix: name of esModule option in source code (#346)
Browse files Browse the repository at this point in the history
evilebottnawi authored Nov 25, 2019

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
1 parent 2a18cba commit 31d6589
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -59,10 +59,10 @@ export default function loader(content) {
this.emitFile(outputPath, content);
}

const esModules =
typeof options.esModules !== 'undefined' ? options.esModules : true;
const esModule =
typeof options.esModule !== 'undefined' ? options.esModule : true;

return `${esModules ? 'export default' : 'module.exports ='} ${publicPath};`;
return `${esModule ? 'export default' : 'module.exports ='} ${publicPath};`;
}

export const raw = true;
19 changes: 19 additions & 0 deletions test/__snapshots__/esModule-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`"esModule" option should work with "Boolean" value equal "false": errors 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "false": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;

exports[`"esModule" option should work with "Boolean" value equal "false": warnings 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "true": errors 1`] = `Array []`;

exports[`"esModule" option should work with "Boolean" value equal "true": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;

exports[`"esModule" option should work with "Boolean" value equal "true": warnings 1`] = `Array []`;

exports[`"esModule" option should work without value: errors 1`] = `Array []`;

exports[`"esModule" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`;

exports[`"esModule" option should work without value: warnings 1`] = `Array []`;
19 changes: 0 additions & 19 deletions test/__snapshots__/esModules-option.test.js.snap

This file was deleted.

4 changes: 2 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ exports[`validate options should throw an error on the "emitFile" option with "t
-> Enables/Disables emit files (https://github.com/webpack-contrib/file-loader#emitfile)."
`;

exports[`validate options should throw an error on the "esModules" option with "true" value 1`] = `
exports[`validate options should throw an error on the "esModule" option with "true" value 1`] = `
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema.
- options.esModules should be a boolean."
- options.esModule should be a boolean."
`;

exports[`validate options should throw an error on the "name" option with "true" value 1`] = `
2 changes: 1 addition & 1 deletion test/validate-options.test.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ describe('validate options', () => {
success: [/image\.png/, 'image.png'],
failure: [true],
},
esModules: {
esModule: {
success: [true, false],
failure: ['true'],
},

6 comments on commit 31d6589

@sepe81
Copy link

@sepe81 sepe81 commented on 31d6589 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting from this commit and with file-loader 5.0.1 and 5.0.2 (but not 5.0.0) I get the "error" from #212

I don't understand why this happens, but guess it's related to the evaluation of the default value. Unfortunately I don't have any isolated example yet.

When I I explicitly set the option esModule to false it works.

          loader: 'file-loader',
          options: {
            esModule: false,
            ...
          }

@alexander-akait
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update css-loader to latest version

@sepe81
Copy link

@sepe81 sepe81 commented on 31d6589 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick reply.

Some days ago I updated to "css-loader": "3.4.1" but with the newest release 3.4.2 AND without esModule: false it doesn't work either.

In my concrete case it is an image resource that doesn't work, so file-loader seems to be the relevant loader.

@alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented on 31d6589 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happens, maybe you can provide a screenshot?

@sepe81
Copy link

@sepe81 sepe81 commented on 31d6589 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I continued to search for similar problems and found [1]. According to [2] esModule is true by default starting with version 5.0.0.

Could it be, that this (breaking change) didn't work in 5.0.0 and has been fixed with 5.0.1? According to [3] this was just a rename from esModules to esModule.

[1] https://stackoverflow.com/questions/59114479/when-i-using-file-loader-and-html-loader-in-webpack-the-src-attr-of-image-gonna
[2] https://github.com/webpack-contrib/file-loader/releases/tag/v5.0.0
[3] #346

@alexander-akait
Copy link
Member

@alexander-akait alexander-akait commented on 31d6589 Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem in html-loader, and will be fixed in next html-loader release, 5.0.1 just fix due typo in source code

Please sign in to comment.