Error: Can't resolve 'normalize-url' in ./node_modules/css-hot-loader/hotModuleReplacement.js
kenilam opened this issue · comments
I am running into some issues and running out of ideas what cause them:
ERROR in ./node_modules/css-hot-loader/hotModuleReplacement.js
Module not found: Error: Can't resolve 'normalize-url' in './node_modules/css-hot-loader'
@ ./node_modules/css-hot-loader/hotModuleReplacement.js 1:19-43
@ ./project/src/App.scss
@ multi ./project/src/App.ts ./project/src/App.scss
The application launch, yet seeing the following issues in inspector:
Uncaught ReferenceError: require is not defined
at Object.<anonymous> (external "normalize-url":1)
at __webpack_require__ (bootstrap 18c624366c5c13843b65:677)
at fn (bootstrap 18c624366c5c13843b65:87)
at Object.<anonymous> (hotModuleReplacement.js:1)
at __webpack_require__ (bootstrap 18c624366c5c13843b65:677)
at fn (bootstrap 18c624366c5c13843b65:87)
at Object.<anonymous> (App.scss:4)
at __webpack_require__ (bootstrap 18c624366c5c13843b65:677)
at fn (bootstrap 18c624366c5c13843b65:87)
at Object.defineProperty.value (bootstrap 18c624366c5c13843b65:723)
And it is preventing the application initialise.
Below are the dependencies in my package.json:
"devDependencies": {
"@types/node": "^8.0.28",
"app-root-path": "^2.0.1",
"autoprefixer": "^7.1.4",
"babel-core": "^6.26.0",
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-root-import": "^5.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-strict-mode": "^6.24.1",
"babel-preset-env": "^1.6.0",
"browser-sync": "^2.18.13",
"browser-sync-webpack-plugin": "^1.2.0",
"clean-css-loader": "^0.1.3",
"clean-webpack-plugin": "^0.1.16",
"connect-history-api-fallback": "^1.3.0",
"css-hot-loader": "^1.3.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.0",
"fast-sass-loader": "^1.3.0",
"file-loader": "^0.11.2",
"fork-ts-checker-webpack-plugin": "^0.2.8",
"gulp": "^3.9.1",
"gulp-help": "^1.6.1",
"gulp-plumber": "^1.1.0",
"gulp-sync": "^0.1.4",
"gulp-util": "^3.0.8",
"html-webpack-plugin": "^2.30.1",
"node-sass": "^4.5.3",
"nodemon": "^1.12.1",
"only-if-changed-webpack-plugin": "0.0.1",
"postcss-loader": "^2.0.6",
"run-sequence": "^2.1.0",
"style-loader": "^0.18.2",
"stylelint": "^8.1.1",
"stylelint-webpack-plugin": "^0.9.0",
"ts-loader": "^2.3.7",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-loader": "^3.5.3",
"typescript": "^2.5.2",
"vinyl-named": "^1.1.0",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.8.2",
"webpack-stream": "^4.0.0"
}
And below is how I configured the use of css-hot-loader in my webpack.config;
{
test : /\.(css|sass|scss)$/,
exclude : /node_modules/,
use : ['css-hot-loader'].concat(ExtractText.extract({
fallback : 'style-loader',
use : [
{
loader : 'css-loader',
options : {
constLoaders : 1,
minimize : true
}
},
{
loader : 'clean-css-loader',
options : {
compatibility : 'ie8',
debug : true,
level : {
2 : {
all : true
}
}
}
},
{
loader : 'postcss-loader',
options : {
plugins : loader => [
AutoPrefixer({
browsers : ['last 2 versions'],
cascade : false
})
]
}
},
{
loader : 'fast-sass-loader',
options : {
includePaths : [
'node_modules',
`${this.path.root.src}`
]
}
}
]
}))
}
Can you fork my example code https://github.com/shepherdwind/css-hot-loader/tree/master/examples/simple ? And modify the config, so I can reproduction the problem you meet.
Sorry, I can't find out the answer from you issue code.
I clone you project, but which can not run fail. When I modify the App.scss, the css file webpack compiled do not change.
So I copy you config to my project, https://github.com/shepherdwind/css-hot-loader/tree/ts-example/examples/ts-example . And this project work fine, css reload have no problem.