Open ajani2001 opened 1 year ago
did you ever find a fix for this? I was a little suprised that copying and pasting the provided code doesn't work.
I was able to work around this issue by using a diffrent loader as the starting point, doing this seems to place the loader in the correct place of the webpack config.
const txtLoader = {
test: /\.txt$/i,
use: 'raw-loader',
};
addAfterLoader(webpackConfig, loaderByName('source-map-loader'), txtLoader);
Have anyone found a fix for this? I have same issue just with ejs-loader instead of html-loader.
Have anyone found a fix for this? I have same issue just with ejs-loader instead of html-loader.
I just inspected the stricture of my existing loader rules via console.dir and inserted the new loader manually in the right place. This is a temporary fix and it might be broken if you change the version of create-react-app or other packages.
This is the corresponding fragment of my config: (ofc you shouldn't remove resolve-url-loader, this is for my project)
configure: (webpackConfig) => {
const htmlLoader = {
test: /\.html$/,
loader: require.resolve('html-loader'),
exclude: [/node_modules/, /public/],
options: { minimize: true, sources: false },
};
// FIXME AFTER THE ISSUE IS FIXED
// https://github.com/dilanx/craco/issues/486
(webpackConfig.module.rules[0] as any).oneOf.splice(0, 0, htmlLoader);
removeLoaders(webpackConfig, loaderByName('resolve-url-loader'));
return webpackConfig;
}
I could fix this issue by adding the loader before another loader instead of file-loader|raw-loader
like babel-loader
. It seems that issue is adding before or after file-loader
and raw-loader
but adding before/after babel-loader
working well.
configure: (webpackConfig) => {
webpackConfig.resolve.extensions.push('.graphql', '.gql');
const graphqlLoader = {
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: require.resolve('graphql-tag/loader'),
}
addBeforeLoader(webpackConfig, loaderByName('babel-loader'), graphqlLoader);
return webpackConfig;
}
@dotamir your solution works for men thank you!
@dotamir Thank you! It works!
I want to add html-loader and I do it according to the recipe:
But my application even doesn`t starts:
It can be reproduced on a blank app just created by create-react-app (with typescript in my case).
I suppose, this is a rare bug, that emerge, when a target loader for addBeforeLoader`s matcher becomes a RuleSetUseItem located in the 'use' array. New loader argument for addBeforeLoader has the type of RuleSetRule, thus, a RuleSetRule is inserted in the 'use' array and breaks the consistency.
The root of problem might me in this cast: https://github.com/dilanx/craco/blob/47fb53b43c355099c2f381cb91693b94be4ee4c8/packages/craco/src/lib/loaders.ts#L49