Typescript 网页包+;打字脚本+;洛达斯
我正在尝试使用typescript和lodash设置webpack,但是当我运行webpack来构建捆绑包时,我得到错误:找不到模块:错误:无法在中解析“lodash” 我正在从“lodash”导入loadas:import*as uu 这是package.jsonTypescript 网页包+;打字脚本+;洛达斯,typescript,webpack,lodash,Typescript,Webpack,Lodash,我正在尝试使用typescript和lodash设置webpack,但是当我运行webpack来构建捆绑包时,我得到错误:找不到模块:错误:无法在中解析“lodash” 我正在从“lodash”导入loadas:import*as uu 这是package.json "devDependencies": { "@types/flux": "^3.1.4", "@types/lodash": "^4.14.91", "@types/lodash-webpack-plugin
"devDependencies": {
"@types/flux": "^3.1.4",
"@types/lodash": "^4.14.91",
"@types/lodash-webpack-plugin": "^0.11.1",
"@types/react": "^16.0.29",
"@types/react-dom": "^16.0.3",
"@types/react-router": "^4.0.19",
.....
.....
"ts-loader": "^3.2.0",
"tslint": "^5.8.0",
"tslint-loader": "^3.5.3",
"tslint-react": "^3.2.0",
"typescript": "^2.6.2",
"url-loader": "^0.6.2",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
},
"dependencies": {
"bootstrap": "^3.3.7",
"flux": "^3.1.3",
"lodash": "^4.17.4",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0"
}
这是webpack.config.js中与ts相关的部分:
resolve: {
// Automatically resolve certain extensions in this case js and jsx.
extensions: ['.js', '.ts', '.tsx']
},
.....
.....
{
test: /\.(ts|tsx)$/, // The Condition must match
exclude: /node_modules/, // The Condition must NOT match
loader: 'ts-loader'
},
这是tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"declaration": false,
"noImplicitAny": false,
"sourceMap": true,
"jsx": "react",
"noLib": false,
"suppressImplicitAnyIndexErrors": true
},
"compileOnSave": false,
"exclude": [
"node_modules"
]
}
我看不出任何明显的原因,除非没有安装依赖项,否则“lodash”中的导入*作为将不起作用。在项目根目录中发布一个
npm安装
,以确保所有依赖项都已安装。多谢各位,我再次运行了npm安装,现在正在运行。