Tôi đang cố gắng biên dịch qua tsc- mà tôi đã cài đặt trên toàn cầu - và tôi gặp lỗi:
~/AppData/Roaming/nvm/v11.15.0/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'.
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
node_modules/@types/node/index.d.ts:170:11
170 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
node_modules/@types/node/index.d.ts:170:11 - error TS2300: Duplicate identifier 'IteratorResult'.
170 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
~/AppData/Roaming/nvm/v11.15.0/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
Found 2 errors.
Tôi đã @types/nodecài đặt phiên bản 10.1.0. ( @latestcó vấn đề riêng ...)
tsconfig.json
{
"compilerOptions": {
"target": "es2018",
"moduleResolution": "node",
"module": "commonjs",
"jsx": "react",
"lib": [
"dom",
"es2018",
"dom.iterable",
"scripthost"
],
"typeRoots": [
"./node_modules/@types",
"./types"
],
"types": [],
"alwaysStrict": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"sourceMap": true,
"outDir": "dist"
},
"files": [
"app/index.tsx"
],
"include": [
"app/**/*.ts",
"app/**/*.tsx",
"test/**/*.ts",
"test/**/*.tsx",
"node_modules/@types/**/*.d.ts",
"./types/**/*.d.ts"
],
"exclude": [
"dist"
]
}
Nếu tôi gỡ cài đặt typescripttoàn cầu và chạy npx tscnó hoạt động, nhưng sẽ không có gì sai khi cài đặt và chạy typescripttrên toàn cầu. Rốt cuộc, đó là toàn bộ điểm của việc cài đặt mọi thứ trên toàn cầu.
Trong khi chờ đợi, tôi có một cách giải quyết là chỉ bí danh tsc (tôi đang sử dụng git bash trong Windows).
alias tsc="path/to/project/node_modules/.bin/tsc.cmd"
