mockdeep / typewiz

Automatically discover and add missing types in your TypeScript code
https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c
1.1k stars 46 forks source link

typewiz-node CLI doesn't work on Ubuntu 16.04 #68

Closed nivertech closed 6 years ago

nivertech commented 6 years ago
$ typewiz-node index.ts 
Error: Cannot find module 'ts-node/dist/_bin'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/${USER}/local/node/lib/node_modules/typewiz-node/src/typewiz-node.ts:8:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

Environment:

$ ts-node -v
ts-node v6.0.0
node v8.11.1
typescript v2.8.1
cache "/tmp/ts-node-e..............."

$ node -v
v8.11.1

$ npm -v
5.8.0

$ uname -a
Linux ${HOST} 4.4.0-119-generic #143-Ubuntu SMP Mon Apr 2 16:08:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
zoehneto commented 6 years ago

The problem seems to be related to installing typewiz-node globally. If I install it locally it works correctly but if I install it with -g to use it on the command line it installs typewiz-node into .npm-global but not its dependencies, so ts-node can't be found.

urish commented 6 years ago

Thanks for reporting!

Does it work if you also npm install -g ts-node typescript ?

nivertech commented 6 years ago

it doesn't work when you install both locally and globally.

The manual workaround for local install is renaming the ts-node executable:

$ npm -g uninstall ts-node
...
$ npm -g uninstall typewiz-node
...
$ npm i ts-node
...
$ npm i typewiz-node
+ typewiz-node@1.0.2
added 23 packages from 19 contributors in 5.064s
$ typewiz-node index.ts
bash: /home/${USER}/local/node/bin/typewiz-node: No such file or directory
$ npx typewiz-node index.ts
Cannot find module 'ts-node/dist/_bin'

$ cd ./node_modules/ts-node/dist/
$ ls
bin.d.ts  bin.js  bin.js.map  index.d.ts  index.js  index.js.map  index.spec.d.ts  index.spec.js  index.spec.js.map
$ ./bin.js 
> 
(To exit, press ^C again or type .exit)
> 
$ cp bin.js _bin.js
$ ./_bin.js 
> 
(To exit, press ^C again or type .exit)
> 
$ # back to project folder
$ cd ../../../
$ npx ts-node
> 
(To exit, press ^C again or type .exit)
> 
$ typewiz-node index.ts
bash: /home/${USER}/local/node/bin/typewiz-node: No such file or directory
$ npx typewiz-node index.ts
⨯ Unable to compile TypeScript
index.ts (40,12): Cannot find name 'require'. (2304)
index.ts (41,11): Cannot find name 'require'. (2304)
index.ts (42,17): Cannot find name 'require'. (2304)
index.ts (43,12): Cannot find name 'require'. (2304)
index.ts (44,10): Cannot find name 'require'. (2304)
...
$
radotzki commented 6 years ago

After some investigating, we found that the issue is with ts-node changed the bin.js file, and removed the underscore. The change was here: https://github.com/TypeStrong/ts-node/commit/7164ab734c73167dce9adc2538e98d3d9999f7f6#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L9

We suggest to remove the underscore in line 8 in "typewiz-node.ts".

GoodnessSquad