gpt4 book ai didi

react ts-loader not working with babel loader webpack(反应TS-装载机不与巴别塔装载机webpack一起工作)

转载 作者:bug小助手 更新时间:2023-10-24 22:42:58 27 4
gpt4 key购买 nike



Trying to use ts-loader with my webpack configuration, but I keep getting errors on the terminal when I try to build.

尝试将ts-Loader与我的webpack配置一起使用,但当我尝试构建时,终端上不断出现错误。


ERROR in ./src/index.ts 4:12
Module parse failed: Unterminated regular expression (4:12)
File was processed with these loaders:
* ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| var ROOT_ID = 'main';
| var App = function () {
> return />;
| };
| var root = createRoot(document.getElementById(ROOT_ID));

ERROR in ...\client\src\index.ts
./src/index.ts 7:10-11
[tsl] ERROR in ...\client\src\index.ts(7,11)
TS1005: '>' expected.

ERROR in ...\client\src\index.ts
./src/index.ts 7:11
[tsl] ERROR in ...\client\src\index.ts(7,12)
TS1161: Unterminated regular expression literal.

...

ERROR in ...\client\src\index.ts
./src/index.ts 12:13-16
[tsl] ERROR in ...\client\src\index.ts(12,14)
TS2749: 'App' refers to a value, but is being used as a type here. Did you mean 'typeof App'?

...
...

ERROR in ...\client\src\containers\home.ts
2:22-42
[tsl] ERROR in ...\client\src\containers\home.ts(2,23)
TS2307: Cannot find module 'components/theatre' or its corresponding type declarations.


My file structure

我的文件结构



- Client
|> babel.config.json
|> tsconfig.json
|> webpack.common.js
... other files

Babel config json

巴别塔配置json


{
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
"plugins": ["babel-plugin-styled-components"]
}

tsconfig.json

Tsconfig.json


{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"module": "es6",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "../static/js",
"sourceMap": true,
"target": "es5"
}
}

webpack.common.js

Webpack.common.js


module.exports = {
entry: ["./src/index.ts"],
output: {
filename: 'bundle.js',
path: path.join(some path)
},
resolve: {
extensions: [".js", ".ts", ".tsx"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
...
}

更多回答
优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com