ts node
来源:4-3 初始化项目 - TypeScript library starter

wiekern
2019-06-26
npm install failed when using typescript-library-starter to init the project
C:\Users\xxx\Desktop\ts-axios>npm install
npm WARN deprecated @types/handlebars@4.1.0: This is a stub types definition. handlebars provides its own type definitions, so you do not need this installed.
> --libraryname--@0.0.0 postinstall C:\Users\xxx\Desktop\ts-axios
> ts-node tools/init
'ts-node' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! --libraryname--@0.0.0 postinstall: `ts-node tools/init`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the --libraryname--@0.0.0 postinstall 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\xxx\AppData\Roaming\npm-cache\_logs\2019-06-25T18_32_02_015Z-debug.log
attempt to solve it by chaninng the version of ts-node to the lastest 8.3.0, then new error appears as below
const pkg = JSON.parse(readFileSync(jsonPackage) as any)
^
SyntaxError: Unexpected token Y in JSON at position 246
at JSON.parse (<anonymous>)
at finalize (C:\Users\xxx\Desktop\ts-axios\tools\init.ts:264:20)
at setupLibrary (C:\Users\xxx\Desktop\ts-axios\tools\init.ts:183:3)
at C:\Users\xxx\Desktop\ts-axios\tools\init.ts:124:7
at C:\Users\xxx\Desktop\ts-axios\node_modules\prompt\lib\prompt.js:336:32
at C:\Users\xxx\Desktop\ts-axios\node_modules\utile\node_modules\async\lib\async.js:154:25
at assembler (C:\Users\YafeiYan\Desktop\ts-axios\node_modules\prompt\lib\prompt.js:333:9)
at C:\Users\xxx\Desktop\ts-axios\node_modules\prompt\lib\prompt.js:342:32
at C:\Users\xxx\Desktop\ts-axios\node_modules\prompt\lib\prompt.js:625:5
at Interface.onLine (C:\Users\xxx\Desktop\ts-axios\node_modules\read\lib\read.js:111:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! --libraryname--@0.0.0 postinstall: `ts-node tools/init`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the --libraryname--@0.0.0 postinstall 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\xxx\AppData\Roaming\npm-cache\_logs\2019-06-25T18_42_04_302Z-debug.log
5回答
-
wiekern
提问者
2019-06-28
实锤了!看了 typescript-library-starter 源码,package.json 中的 "author" 字段是通过 `git config user.name` 获取。之前失败是因为得到的用户名是带前缀“AzureAD\”,这里的"\"放入到 package.json 中导致 json 文件不合法,从而初始化会失败。下图是我设置完全局 git 用户名之后,初始化成功!
012019-06-28 -
wiekern
提问者
2019-06-28
node: 8.15.1
npm: 6.4.1
OS: Windows 10
account: administrator (本地账号)
在新环境下重新使用 typescript-library-starter 初始化项目成功!使用 BeyondCompare 比较了两个项目文件,发现如下异同
1.
2. 某个配置文件和 git 用户名相关字段不同,新项目为空,老项目因为用户名前缀带了微软 “AzureAD\”这样的前缀,因为用的是hotmail邮箱登陆的用户,并不是administrator这样的本地用户,而且在administrator环境下项目初始化成功的,所以我猜是因为这个前缀导致项目初始化过程中出问题。
012019-06-28 -
ustbhuangyi
2019-06-26
你的 node 和 npm 版本是多少?
032019-06-27 -
wiekern
提问者
2019-06-26
虽然出错,但是目录结构看起来是完整的。
00 -
wiekern
提问者
2019-06-26
```
> ts-node tools/init
Hi! You're almost ready to make the next great TypeScript library.
Would you like it to be called "typescript-axios"? [Yes/No]: yes
Thanks for the info. The last few changes are being made... hang tight!
AzureAD\xxx
xxx@gmail.com
Removed
.git
.all-contributorsrc
.gitattributes
tools/init.ts
Modified
LICENSE
package.json
rollup.config.ts
test/library.test.ts
tools/gh-pages-publish.ts
Renamed
src/library.ts => src/typescript-axios.ts
test/library.test.ts => test/typescript-axios.test.ts
Finalizing
Initialized empty Git repository in C:/Users/xxx/Desktop/typescript-axios/.git/
C:\Users\xxx\Desktop\typescript-axios\tools\init.ts:264
const pkg = JSON.parse(readFileSync(jsonPackage) as any)
^
SyntaxError: Unexpected token Y in JSON at position 289
at JSON.parse (<anonymous>)
at finalize (C:\Users\xxx\Desktop\typescript-axios\tools\init.ts:264:20)
at setupLibrary (C:\Users\xxx\Desktop\typescript-axios\tools\init.ts:183:3)
at C:\Users\xxx\Desktop\typescript-axios\tools\init.ts:124:7
at C:\Users\xxx\Desktop\typescript-axios\node_modules\prompt\lib\prompt.js:336:32
at C:\Users\xxx\Desktop\typescript-axios\node_modules\utile\node_modules\async\lib\async.js:154:25
at assembler (C:\Users\xxx\Desktop\typescript-axios\node_modules\prompt\lib\prompt.js:333:9)
at C:\Users\xxx\Desktop\typescript-axios\node_modules\prompt\lib\prompt.js:342:32
at C:\Users\xxx\Desktop\typescript-axios\node_modules\prompt\lib\prompt.js:625:5
at Interface.onLine (C:\Users\xxx\Desktop\typescript-axios\node_modules\read\lib\read.js:111:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! --libraryname--@0.0.0 postinstall: `ts-node tools/init`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the --libraryname--@0.0.0 postinstall 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\xxx\AppData\Roaming\npm-cache\_logs\2019-06-25T19_52_31_495Z-debug.log
```
重新初始化一次项目,老问题。
00
相似问题