![](/img/trans.png)
[英]Why am I getting "TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function" error when using reactjs hooks?
[英]Why am I getting Webpack 'module not found' error?
我正在重構具有有效 webpack 捆綁的項目。 基本上,我正在嘗試更改項目的根源文件夾,但我遇到了問題。 我已經調試了很長時間,但我看不到我缺少什么。
在我的tsconfig.json文件中,我有以下設置
"baseUrl": "./",
"paths": {
"src/*": [
"src/*"
],
"test/*": [
"test/*"
]
}
在webpack.common.js文件中,我有以下內容
const includePaths = ['node_modules', 'src'];
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
modules: includePaths,
},
我的源文件夾位於項目的根目錄中。 基本上我應該可以使用./src
這就是我捆綁的方式:
rm -rf ./build && webpack --config webpack.dev.js
webpack.dev.js
merge(common, config, {
entry: {
main: [
`${__dirname}/src/environment`,
'webpack-hot-middleware/client?path=__webpack_hmr&dynamicPublicPath=true',
`${__dirname}/src/main`,
],
},
當我在監視模式下運行捆綁程序時,我看到如下內容:
These dependencies were not found:
src/<somefolder>/<somefile> in ./src/<somefolder>/<somefile.tsx>
Module not found: Error: Can't resolve ...
奇怪的是,當 src 文件夾位於另一個文件夾下時,例如。 前端/src,它捆綁起來沒有問題。 我懷疑 tsconfig 中有問題,但我無法弄清楚。 有人可以幫忙嗎?
添加這樣的別名有效,但我真的不明白沒有別名的舊版本是如何工作的。
alias: {
src: path.resolve(__dirname, 'src'),
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.