CanvasJS 沒有 npm 包,因此您必須手動下載它才能在本地使用它。所以,我做到了,將canvasjs.min.js添加到我的項目中并將其導入到我的組件中。但它不起作用: ERROR in src/app/survey/survey.component.ts:8:27 - error TS2307: Cannot find module 'src/assets/canvasjs.min.js'. import * as CanvasJS from 'src/assets/canvasjs.min.js'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~這是我的樹文件夾:- src -- app --- survey ---- survey.component.ts -- assets --- canvasjs.min.js在我的組件中,我包含了這樣的庫:import * as CanvasJS from 'src/assets/canvasjs.min.js';這是我的項目根目錄中的所有 jsons 配置: tsconfig.spec.json { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": [ "jasmine", "node" ] }, "files": [ "src/test.ts", "src/polyfills.ts" ], "include": [ "src/**/*.spec.ts", "src/**/*.d.ts" ]}tsconfig.json{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "lib": [ "es2018", "dom" ] }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true }}tsconfig.app.json{ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "types": [] }, "files": [ "src/main.ts", "src/polyfills.ts" ], "include": [ "src/**/*.d.ts" ]}我已經(jīng)嘗試過:在 angular.json 的腳本中添加路徑將 .js 移動到任何文件夾中的任何位置用絕對路徑和相對路徑改變我的路徑更改 baseUrl
無法在 Angular 9 中導入 CanvasJS
躍然一笑
2022-10-27 14:49:51