DaGhostman / ts-php-inspections

An inspecion tool for PHP written in TS
MIT License
6 stars 2 forks source link

can't run samples #1

Closed ichiriac closed 7 years ago

ichiriac commented 7 years ago

Hi @DaGhostman,

When I run it from the command line, I got this error :

/usr/local/lib/node_modules/ts-node/src/index.ts:312
          throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
                ^
TSError: ⨯ Unable to compile TypeScript
bin/php-inspections.ts (3,21): Cannot find module 'fs'. (2307)
bin/php-inspections.ts (9,5): Cannot find name 'process'. (2304)
bin/php-inspections.ts (18,5): Cannot find name 'process'. (2304)
bin/php-inspections.ts (20,5): Cannot find name 'process'. (2304)
bin/php-inspections.ts (23,20): Cannot find name 'process'. (2304)
bin/php-inspections.ts (23,33): Cannot find name 'process'. (2304)
bin/php-inspections.ts (23,75): Cannot find name 'process'. (2304)
bin/php-inspections.ts (23,88): Cannot find name 'process'. (2304)
bin/php-inspections.ts (27,5): Cannot find name 'process'. (2304)
bin/php-inspections.ts (36,5): Cannot find name 'process'. (2304)
bin/php-inspections.ts (40,14): Cannot find name 'process'. (2304)
bin/php-inspections.ts (47,17): Cannot find name 'process'. (2304)
bin/php-inspections.ts (48,28): Cannot find name 'process'. (2304)
    at getOutput (/usr/local/lib/node_modules/ts-node/src/index.ts:312:17)
    at /usr/local/lib/node_modules/ts-node/src/index.ts:343:18
    at Object.compile (/usr/local/lib/node_modules/ts-node/src/index.ts:502:17)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:406:44)
    at Module._extensions..js (module.js:417:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:409:12)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/ts-node/src/_bin.ts:184:12)

I'm running it from ubuntu 16, ts-node v1.7.2 and node v4.2.6.

Any clue ?

DaGhostman commented 7 years ago

Just was able to reproduce the issue. Turns out I have some global types that ts-node uses and that ended in the tool not working (I was soo excited :laughing: ) + I was able to identify a slight incompatibility with node:4 (I was using 6 while developing) the fix takes a few steps actually:

  1. Update the devDependencies to ask for ~4.0 of `@types/node"
  2. Point to set typeRoots in tsconfig.json to node_modules/@types/
  3. add import * as process from 'process' in the bin/php-inspections.ts

I will commit the fix in a few mins


As far as I can tell 0a71ec9 resolves the issue, mind verifying for me :)

ichiriac commented 7 years ago

Iit's better, the list of error is smaller :

/usr/local/lib/node_modules/ts-node/src/index.ts:312
          throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
                ^
TSError: ⨯ Unable to compile TypeScript
bin/php-inspections.ts (3,21): Cannot find module 'fs'. (2307)
bin/php-inspections.ts (4,26): Cannot find module 'process'. (2307)
    at getOutput (/usr/local/lib/node_modules/ts-node/src/index.ts:312:17)
    at /usr/local/lib/node_modules/ts-node/src/index.ts:343:18
    at Object.compile (/usr/local/lib/node_modules/ts-node/src/index.ts:502:17)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:406:44)
    at Module._extensions..js (module.js:417:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:409:12)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/ts-node/src/_bin.ts:184:12)

maybe it's the same reason : https://github.com/Microsoft/TypeScript/issues/5812

ichiriac commented 7 years ago

found the solution here : http://stackoverflow.com/questions/37260901/how-to-find-module-fs-in-ms-code-with-typescript

npm install typings --global
typings install dt~node --global --save

And after everything runs well :smile:

DaGhostman commented 7 years ago

Lol I was just getting desperate... I was going to set up docker just to reproduce :smile: Anyway, Ill add it to the README


But still it should see the typings inside the node_modules directory, unless I am missing something with ts-node

ichiriac commented 7 years ago

oups, i've made a npm install after getting the unable to find php-parser error :(