Closed nivertech closed 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.
Thanks for reporting!
Does it work if you also npm install -g ts-node typescript
?
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)
...
$
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".
Environment: