You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Loader can't modify resource type without accessing private API #7057
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Now that webpack has the concept of module type (JSON, JS, CSS, WASM), loaders which convert resources from one type to another do not work without either requiring the end user to modify their config (i.e. for a loader that converts to JS the user must add type: 'javascript/auto' to their config) or resorting to modifying private internal webpack APIs. The former leaks internal loader implementation details onto the user and doesn't work if the user wants to pipe the output of that loader into another, while the latter is brittle and prone to breakage in future webpack versions.
What is the expected behavior?
Webpack should support loaders that convert between resource types, probably via the loader API.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Node v8.11.0
webpack 4.5.0
Linux
Reacted by Yaroslav Kiliba, yelo, najimammeri-veonum, Vincent Le Biannic and Ryan Berdeen
@Lyrkan@evilebottnawi
Im wondering if you might be able to provide a hint here. Im attempting to upgrade the translation loader used at my company- which mentioned this git issue.
The error getting thrown in Webpack 5 is as followed
Module parse failed: Abstract method Parser.parse. Must be overridden.
File was processed with these loaders:
* ./loaders/lingui.js
It sounds like I need to replace the this._module.parser with another one? Does anyone have any hints on how I could achieve this?
The likely code in question is
// Webpack 4 uses json-loader automatically, which breaks this loader because it
// doesn't return JSON, but JS module. This is a temporary workaround before
// official API is added (https://github.com/webpack/webpack/issues/7057#issuecomment-381883220)
// See https://github.com/webpack/webpack/issues/7057
if (JavascriptParser && JavascriptGenerator) {
this._module.type = "javascript/auto";
this._module.parser = new JavascriptParser();
this._module.generator = new JavascriptGenerator();
}
@ScriptedAlchemy I haven't tested it with the latest version of Webpack 5 but it worked a while ago:
constLoaderDependency=require('webpack/lib/dependencies/LoaderDependency');constrequiredType='javascript/auto';if(this._module.type!==requiredType){// Try to retrieve the factory used by the LoaderDependency type// which should be the NormalModuleFactory.constfactory=this._compilation.dependencyFactories.get(LoaderDependency);if(factory===undefined){thrownewError('Could not retrieve module factory for type LoaderDependency');}this._module.type=requiredType;this._module.generator=factory.getGenerator(requiredType);this._module.parser=factory.getParser(requiredType);}
Activity
[-]Loader can[/-][+]Loader can't modify resource type without accessing private API[/+]Support Webpack 4
Support Webpack 4
sokra commentedon Apr 17, 2018
Makes sense. Maybe a
this.setModuleType("javascript/auto")in the loader API.Do you want to send a PR? Note that module type set by loader should not leak between rebuilds. It need to be reset on unbuild.
Support Webpack 4
Support Webpack 4
fix: set module type in webpack loader
webpack-bot commentedon Mar 1, 2019
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon Mar 1, 2019
Bump
webpack-bot commentedon Sep 7, 2019
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
alexander-akait commentedon Sep 7, 2019
bump
2 remaining items
Lyrkan commentedon Dec 8, 2019
Bump so it doesn't get closed
I tried adding the new method here: #10097
fix: set module type in webpack loader
webpack-bot commentedon Mar 24, 2020
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.
Lyrkan commentedon Mar 25, 2020
@evilebottnawi I think it can be closed based on @sokra's comment here: #10097 (comment)
alexander-akait commentedon Mar 25, 2020
Yes, you are right, in webpack@5 it is possible to achieve that using plugin (you can look on asset or json plugin)
ScriptedAlchemy commentedon Jul 8, 2020
@Lyrkan @evilebottnawi
Im wondering if you might be able to provide a hint here. Im attempting to upgrade the translation loader used at my company- which mentioned this git issue.
The error getting thrown in Webpack 5 is as followed
https://gist.github.com/ScriptedAlchemy/4d3f8e63d16d9b9150e30e8083d91048
It sounds like I need to replace the this._module.parser with another one? Does anyone have any hints on how I could achieve this?
The likely code in question is
Lyrkan commentedon Jul 9, 2020
@ScriptedAlchemy I haven't tested it with the latest version of Webpack 5 but it worked a while ago:
ScriptedAlchemy commentedon Jul 9, 2020
@Lyrkan thank youuuuuuuu ill try this out