asz*_*ski 7 compiler-errors typescript bootstrap-4 type-definition popper.js
我试图建立一个TypeScript项目并在Visual Studio Code中与Popper,jQuery和Knockout一起使用bootstrap 4 。
我安装了剔除,jquery和bootstrap类型定义,
npm install -–save @types/knockout
npm install -–save @types/jquery
npm install --save @types/bootstrap
Run Code Online (Sandbox Code Playgroud)
在require.js配置中引用了JS文件
declare var require: any;
require.config({
paths: {
"knockout": "externals/knockout-3.5.0",
"jquery": "externals/jquery-3.3.1.min",
"popper.js": "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js",
"bootstrap": "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
}
})
Run Code Online (Sandbox Code Playgroud)
我的tsconfig.json是这样的:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["types/*"]
},
"outDir": "./built/",
"sourceMap": true,
"noImplicitAny": true,
"module": "amd",
"target": "es5"
},
"files":[
"src/require-config.ts",
"src/hello.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我去编译该项目,但出现以下错误:
node_modules/@types/bootstrap/index.d.ts:9:25 - error TS2307: Cannot find module 'popper.js'.
9 import * as Popper from "popper.js";
~~~~~~~~~~~
Found 1 error.
The terminal process terminated with exit code: 1
Run Code Online (Sandbox Code Playgroud)
似乎我的Bootstrap类型定义文件编译失败,因为它找不到popper.js模块。
该popper.js模块是在我的@types文件夹
node_modules
|-@types
| |- bootstrap
| |-index.d.ts (this is failing)
|- popper.js
|- index.d.ts (popper.js type definition)
Run Code Online (Sandbox Code Playgroud)
如何告诉TypeScript编译器引导类型定义正在寻找的popper.js位于层次结构中的较高位置?
我什至无法找到任何答案。因此,或者我偶然发现了一个没人遇到过的错误(不太可能),或者是我刚接触Typescript,我的环境设置不正确,并且错过了其他所有人都可以接受的非常基本的设置步骤,因此没有人可以不得不问(很有可能)。
我该怎么做才能解决此问题?
您有两个选择:
"module": "amd"配置选项或"moduleResolution": "node"选项。第二个选项如下所示:
"moduleResolution": "node",
"module": "amd",
Run Code Online (Sandbox Code Playgroud)
这些选项为何起作用?
简而言之,当我们使用amd模块时,默认的模块解析策略是Classic而不是Node。两者之间的重要区别在于,节点策略将目录名称识别为模块,而经典策略则不能。
这里有关于模块解析策略的更多信息。
| 归档时间: |
|
| 查看次数: |
1166 次 |
| 最近记录: |