[英]Conflict between RequireJs and NodeJS definitions in Typescript
我從Definitely Typed獲得了Typescript RequireJS定義 - 它的環境聲明Require與NodeJs命令“require”沖突。 這是聲明和錯誤:
宣言:
declare var require: Require;
錯誤:
C:/.../require.d.ts(320,13): error TS2134: Subsequent variable declarations must have the same type. Variable 'require' must be of type '{ resolve(id: string): string; cache: any; extensions: any; main: any; (id: string): any; }', but here has type 'Require'.
那是真實的。 我必須做的只是使用declare var require:any而不是引用nodejs或RequireJS。
如果你能在這里打開一個錯誤,將不勝感激: https : //github.com/borisyankov/DefinitelyTyped
它之所以棘手,是因為您實際上並沒有在同一環境中同時擁有node和RequireJS。 這是我們需要支持的編譯時重用的東西。
我試圖在我的應用程序中集成monaco-editor時遇到了這個問題。 解決方法非常簡單。
在html中包含require.js
或loader.js
之后插入此行<script>window.requirejs = window.require;</script>
。
然后在您要使用requirejs的.ts文件中,將所有require
替換為requirejs
。 此別名已在require.d.ts
定義
完成!
我有這個問題,並從typings.json中刪除了這個
"require": "registry:dt/require#2.1.20+20160316155526"
不確定它是如何進入我的項目的,但我沒有使用require客戶端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.