请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

ts node

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

正在回答 回答被采纳积分+3

5回答

提问者 wiekern 2019-06-28 00:59:25

实锤了!看了 typescript-library-starter 源码,package.json 中的 "author" 字段是通过 `git config user.name` 获取。之前失败是因为得到的用户名是带前缀“AzureAD\”,这里的"\"放入到 package.json 中导致 json 文件不合法,从而初始化会失败。下图是我设置完全局 git 用户名之后,初始化成功!

https://img1.sycdn.imooc.com//szimg/5d14f4fa0001175e11630371.jpg

https://img1.sycdn.imooc.com//szimg/5d14f5e10001d13912440859.jpg


0 回复 有任何疑惑可以回复我~
  • 赞从根源上去解决问题的思路
    回复 有任何疑惑可以回复我~ 2019-06-28 10:39:03
提问者 wiekern 2019-06-28 00:31:39

node: 8.15.1

npm: 6.4.1

OS: Windows 10

account: administrator (本地账号)

在新环境下重新使用 typescript-library-starter 初始化项目成功!使用 BeyondCompare 比较了两个项目文件,发现如下异同

1.

https://img1.sycdn.imooc.com//szimg/5d14ee4f00018ab813920098.jpg 

2. 某个配置文件和 git 用户名相关字段不同,新项目为空,老项目因为用户名前缀带了微软 “AzureAD\”这样的前缀,因为用的是hotmail邮箱登陆的用户,并不是administrator这样的本地用户,而且在administrator环境下项目初始化成功的,所以我猜是因为这个前缀导致项目初始化过程中出问题。

0 回复 有任何疑惑可以回复我~
  • 提问者 wiekern #1
    上面图中左为新项目(成功初始化的),右边是老项目(失败的)
    回复 有任何疑惑可以回复我~ 2019-06-28 00:32:33
ustbhuangyi 2019-06-26 10:13:51

你的 node 和 npm 版本是多少?

0 回复 有任何疑惑可以回复我~
  • 提问者 wiekern #1
    node v8.15.1
    npm 6.4.1
    回复 有任何疑惑可以回复我~ 2019-06-26 13:11:07
  • ustbhuangyi 回复 提问者 wiekern #2
    你的操作步骤是怎样的,以及你目前安装出来的项目能正常运行吗
    回复 有任何疑惑可以回复我~ 2019-06-26 16:43:38
  • 提问者 wiekern 回复 ustbhuangyi #3
    步骤完全按你的视频里来的,项目运行没啥问题。
    但是还有问题,我加了新的依赖再npm install时,又报错。
    
    > ts-node tools/init
    
    Error: Cannot find module 'C:\Users\YafeiYan\Desktop\ts-axios\tools\init'
        at Function.Module._resolveFilename (module.js:548:15)
        at Function.Module._load (module.js:475:25)
        at Function.Module.runMain (module.js:694:10)
        at Object.<anonymous> (C:\Users\YafeiYan\Desktop\ts-axios\node_modules\ts-node\src\bin.ts:157:12)
        at Module._compile (module.js:653:30)
        at Object.Module._extensions..js (module.js:664:10)
        at Module.load (module.js:566:32)
        at tryModuleLoad (module.js:506:12)
        at Function.Module._load (module.js:498:3)
        at Function.Module.runMain (module.js:694:10)
    回复 有任何疑惑可以回复我~ 2019-06-27 23:41:56
提问者 wiekern 2019-06-26 05:56:25

https://img1.sycdn.imooc.com//szimg/5d12986600015b3302820579.jpg虽然出错,但是目录结构看起来是完整的。

0 回复 有任何疑惑可以回复我~
提问者 wiekern 2019-06-26 03:58:33

```

> 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

```

重新初始化一次项目,老问题。


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信