[英]How do I use @types/three for ts with webpack?
I have a NodeJS project I want to compile using webpack for a client side web app, for browsers.我有一个 NodeJS 项目,我想使用 webpack 编译客户端 web 应用程序,用于浏览器。
I have installed webpack, and ts-loader.我已经安装了 webpack 和 ts-loader。 I was able to compile my project, but I am getting errors in my ts file that the class types of THREEjs are not recognized.
我能够编译我的项目,但是我的 ts 文件中出现错误,即无法识别 THREEjs 的 class 类型。 I have the @types/three package installed but I can't figure how to make ts-loader use that.
我安装了@types/three package,但我不知道如何让 ts-loader 使用它。
Here are my config files: package.json这是我的配置文件:package.json
{
"name": "Lib",
"version": "1.0.0",
"description": "",
"main": "distribute/Lib.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel src/index.html --port 5000"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/three": "^0.103.2",
"browserify": "^17.0.0",
"javascript-obfuscator": "^2.10.4",
"parcel": "^2.0.0-nightly.610",
"parcel-plugin-static-files-copy": "^2.5.1",
"ts-loader": "^8.0.17",
"typescript": "^3.9.9",
"webpack": "^5.24.2",
"webpack-cli": "^4.5.0"
},
"dependencies": {
"@types/node": "^14.14.31",
"express": "^4.17.1",
"node-fetch": "^3.0.0-beta.9",
"save": "^2.4.0",
"three": "^0.118.3",
"three-orbitcontrols": "^2.110.3"
}
}
webpack.config.js webpack.config.js
const path = require('path');
module.exports = {
entry: './src/Lib.js',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
tsconfig.json tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"jsx": "react",
"types": [
"three"
],
"allowJs": true
}
}
This is an example of the THREE.js types error I get这是我得到的 THREE.js 类型错误的一个示例
TS2694: Namespace '"I:\NodeJs\Project\node_modules\three\build\three"' has no exported member 'DataTexture'. TS2694:命名空间 '"I:\NodeJs\Project\node_modules\three\build\three"' 没有导出的成员 'DataTexture'。
Ok, what I did is: npm uninstall '@types/three' Then: npm install '@types/three'好的,我所做的是: npm uninstall '@types/three' 然后: npm install '@types/three'
Basically uninstalling the types then installing them again did the trick.基本上卸载类型然后再次安装它们就可以了。 Now I don't care THREE.js types related errors.
现在我不在乎 THREE.js 类型相关的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.