This webpack error occurs when Create React App or a custom webpack configuration encounters a file type it cannot process because no loader is configured for it. Common triggers include importing unsupported file types, incorrect babel configuration, or missing type declarations for assets like SVGs or CSS modules.
Webpack is a module bundler that transforms and bundles your application files. To process different file types (JavaScript, TypeScript, CSS, images, SVG, etc.), webpack relies on loaders - plugins that teach webpack how to transform specific file types into valid JavaScript modules. This error appears when webpack encounters a file it does not know how to process because no loader is configured for that file type in your webpack configuration. In Create React App, most loaders are pre-configured, but this error can still occur when importing non-standard file types, when dependencies have incompatible configurations, or when the webpack configuration has been customized incorrectly. The error message typically includes the file path and line number where the problematic import occurs, making it easier to identify which file type is causing the issue.
Read the full error message carefully. It will show the exact file path and line number causing the issue. Look for the file extension (.svg, .scss, .tsx, etc.) and note which import statement is failing.
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type,
currently no loaders are configured to process this file.
> <svg xmlns="http://www.w3.org/2000/svg">...
at /project/src/components/Icon.svg:1:0This tells you that a .svg file at the specified path is the problem.
Create a custom.d.ts or react-app-env.d.ts file at the root of your src directory with module declarations for asset types. This tells TypeScript how to handle non-code imports.
// src/custom.d.ts
declare module "*.svg" {
const content: string;
export default content;
}
declare module "*.png" {
const content: string;
export default content;
}
declare module "*.jpg" {
const content: string;
export default content;
}
declare module "*.module.css" {
const classes: { [key: string]: string };
export default classes;
}Ensure this file is included in your tsconfig.json:
{
"include": ["src/**/*", "src/custom.d.ts"]
}Corrupted or mismatched package versions can cause loader configuration issues. Remove node_modules and the lock file, then reinstall.
rm -rf node_modules
rm package-lock.json # or yarn.lock / pnpm-lock.yaml
npm install # or yarn / pnpm installIf using Create React App, ensure you have a compatible version of react-scripts installed.
If you have a custom .babelrc or babel.config.js file, ensure it includes the React preset. This is critical for processing JSX syntax.
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}If these presets are missing, install them:
npm install --save-dev @babel/preset-react @babel/preset-envCreate React App supports CSS out of the box but not SCSS/SASS. If you need to use .scss or .sass files, install the sass package:
npm install sassThen rename your CSS files from .css to .scss and import them normally:
import "./styles.scss";Create React App will automatically detect and use the sass loader.
If you ejected Create React App or are using a custom webpack config, ensure you have rules for all file types you are importing. Check your webpack.config.js:
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-react", "@babel/preset-env"]
}
}
},
{
test: /\.svg$/,
type: "asset/resource"
},
{
test: /\.(png|jpg|jpeg|gif)$/,
type: "asset/resource"
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
}
};Ensure the test regex matches your file extensions, including both uppercase and lowercase variants if needed.
If you are using a monorepo (Lerna, Yarn workspaces, or pnpm workspaces), webpack may try to process files from linked packages. You may need to adjust the babel-loader include path or add symlinked packages to nohoist.
In your root package.json:
{
"workspaces": {
"packages": ["packages/*"],
"nohoist": ["**/babel-loader", "**/react-scripts"]
}
}Or in a custom webpack config, explicitly include your workspace packages:
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "../shared-components")
],
use: "babel-loader"
}Some webpack configurations use regex that only matches lowercase extensions. If you have files with uppercase extensions like .JSX or .TSX, either rename them to lowercase or update the webpack loader regex:
// BEFORE - only matches lowercase
{ test: /\.jsx?$/ }
// AFTER - matches both upper and lowercase
{ test: /\.[jJ][sS][xX]?$/ }Renaming to lowercase is usually the better solution for consistency.
In Create React App, webpack configuration is intentionally hidden to simplify setup. If you need custom loader configurations, you have three options: (1) eject using npm run eject, which exposes the full webpack config but is irreversible; (2) use react-app-rewired or craco to override configuration without ejecting; or (3) migrate to a more flexible build tool like Vite. For production applications, consider using Vite instead of Create React App, as it provides better performance and more flexible configuration. When working with SVGs, you can import them as React components using @svgr/webpack (included in Create React App by default) by importing with a named import: import { ReactComponent as Icon } from "./icon.svg". If you encounter this error in a CI/CD pipeline but not locally, check that your build environment has the same Node.js version, npm/yarn version, and package-lock.json committed to the repository. The error can also occur when third-party libraries include unexpected file types; in this case, you may need to configure webpack to ignore or transform those specific files.
React Hook useCallback has a missing dependency: 'variable'. Either include it or remove the dependency array react-hooks/exhaustive-deps
React Hook useCallback has a missing dependency
Cannot use private fields in class components without TS support
Cannot use private fields in class components without TS support
Cannot destructure property 'xxx' of 'undefined'
Cannot destructure property of undefined when accessing props
useNavigate() may be used only in the context of a <Router> component.
useNavigate() may be used only in the context of a Router component
Cannot find module or its corresponding type declarations
How to fix "Cannot find module or type declarations" in Vite