npm startでerror TS1084発生
対処法を備忘録
エラー内容
node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! angular-quickstart@1.0.0 build: `tsc -p src/`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\akanbe\AppData\Roaming\npm-cache\_logs\2021-03-06T03_06_34_114Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! angular-quickstart@1.0.0 prestart: `npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\akanbe\AppData\Roaming\npm-cache\_logs\2021-03-06T03_06_34_141Z-debug.log
修正箇所
index.d.ts
// Type definitions for Node.js 6.14
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Wilco Bakker <https://github.com/WilcoBakker>
// Thomas Bouldin <https://github.com/inlined>
// Sebastian Silbermann <https://github.com/eps1lon>
// Alorel <https://github.com/Alorel>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Sander Koenders <https://github.com/Archcry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// NOTE: These definitions support NodeJS and TypeScript 3.2 and above.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2
// Reference required types from the default lib:
/// <reference lib="es2015" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// TypeScript 3.2-specific augmentations:
以下2行を修正
■修正前
index.d.ts
/// <reference lib="es2015" />
/// <reference path="base.d.ts" />
■修正後
index.d.ts
// <reference lib="es2015" />
// <reference path="base.d.ts" />
これで動くようになった
(202305 追記)
新たにやり直したところ別のエラーが発生
エラー内容
# npm start
> angular-quickstart@1.0.0 prestart
> npm run build
> angular-quickstart@1.0.0 build
> tsc -p src/
node_modules/@types/cors/index.d.ts(43,52): error TS1005: ',' expected.
node_modules/@types/cors/index.d.ts(49,44): error TS1005: ',' expected.
node_modules/@types/cors/index.d.ts(49,47): error TS1005: ',' expected.
node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax.
■修正内容
quickstart\package.json
// 前
"typescript": "~2.1.0"
// 後
"typescript": "~2.3.0"
quickstart\node_modules@types\node\index.d.ts
// 前
/// <reference lib="es2015" />
// 後
// <reference lib="es2015" />