我在我的代码中使用了此lib
lib
我在这样的项目中添加了打字
https://www.npmjs.com/package/@types/accounting
并将其包括在这样的.ts文件中
import accounting from "accounting";
我在 /node_modules/@types/accounting
但是当我尝试运行项目时。我的网页显示此
./app/javascript/components/helpers.ts
Module not found: Error: Can't resolve 'accounting' in '/Users/nemesises/Documents/GitHub/falco-web/app/javascript/components'
@ ./app/javascript/components/helpers.ts 1:0-36
@ ./app/javascript/components/itinerary/scripts/hotel_results.ts
@ ./app/javascript/components/step1/step1.ts
@ ./app/javascript/components/step1/index.js
@ ./app/javascript/packs/step1.js
@ multi (webpack)-dev-server/client?http://localhost:3035 ./app/javascript/packs/step1.js
tsconfig.json文件
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"typeRoots": [
"./node_modules/@types"
],
"types": [ "jquery", "accounting" ],
"lib": ["es6", "dom"],
"allowSyntheticDefaultImports": true,
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
我如何修复它?
使用Typescript时,必须安装模块,和模块本身的类型。最好是这样,因此将在devDependencies
下添加类型,因为它们在运行时未使用。添加实际的模块以在运行时使用它,添加类型,以便打字条可以正确检查。
npm install accounting
npm install --save-dev @types/accounting