-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Adding a loader results in Webpack "Invalid configuration object" error in some cases #486
Comments
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. |
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: 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 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:
craco/packages/craco/src/lib/loaders.ts
Line 49 in 47fb53b
The text was updated successfully, but these errors were encountered: