4

Asking for an advise on how to debug this compiler error:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ******@1.1.0 dev: `NODE_ENV=development ts-node ./src/server.ts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ******@1.1.0 dev 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:

this appears when running ts-node ./src/server.ts or node build/server.js

tsc works without errors.

tsconfig.json:

{
   "compilerOptions": {
      "lib": [
         "es2018",
         "dom",
         "esnext.asynciterable"
      ],
      "target": "es2018",
      "module": "commonjs",
      "outDir": "build",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "esModuleInterop": true,
      "sourceMap": false,
      "rootDirs": ["src", "../shared"]
//      "rootDir": "src"
   },
   "exclude": [
      "node_modules",
      "**/*.spec.ts",
      "**/*.test.ts"
   ],
   "references": [
      { "path": "../shared" }
   ]
}

I did made some changes in tsconfig which i suppose cause some imports to fail, however the codebase is huge and i really need some pointers to the exact lines in code which caused the error. especially confusing the tsc runs without errors.

UPDATE:

The issue was with some imports and fixed, However facing similar one again. Know the reason of the current issue - for some reason the imports from shared project (as in here https://www.typescriptlang.org/docs/handbook/project-references.html) are not loaded (despite that they are working in other modules and tsconfig.json is the same with other modules). no particular error, just this npm ERR! code ELIFECYCLE npm ERR! errno 1.

Question:

However the main question of this topic is not the solution of the particularly this problem, but how to debug this kind of import problems where all available log is basically npm ERR! code ELIFECYCLE npm ERR! errno 1. I am facing this kind of issues periodically and every time it takes a lot of time to resolve since the only way to debug i know about is to comment chunks of code which might be associated with the possibly failed imports and sometimes this process could take hours.

user1935987
  • 2,660
  • 5
  • 37
  • 83
  • https://stackoverflow.com/questions/42308879/npm-err-code-elifecycle – nayakam Oct 16 '19 at 05:27
  • yeah i tried to follow suggestions from there, doesn't help. – user1935987 Oct 16 '19 at 05:30
  • If you're trying that from windows, it won't work. Use the package [cross-env](https://www.npmjs.com/package/cross-env) to do that – darklightcode Oct 16 '19 at 06:41
  • from linux, but it's not related to the env variables at all. – user1935987 Oct 16 '19 at 06:50
  • Did you try adding 'd's to the command line? e.g. [`-d`, `-dd` or even `-ddd`](https://docs.npmjs.com/misc/config#shorthands-and-other-cli-niceties)? Or you could add [diagnostics, extendedDiagnostics](https://www.typescriptlang.org/docs/handbook/compiler-options.html) on typescript `compilerOptions` – Marinos An Oct 21 '19 at 10:15
  • 1
    Most of the time the console output before this output defines the error. But is there also nothing have a look in the log file which npm generates on error. The location is also display after "npm ERR! A complete log of this run can be found in:" – Mert Oct 21 '19 at 14:15
  • yeah but that is a complete log output of the error. starting from `npm ERR! code ELIFECYCLE`, ending `can be found in:` path. log file simply contains the same message. again, i'm not talking about the particular issue here, but about how to debug such kind of issues when there is basically no debug output available. – user1935987 Oct 21 '19 at 14:58
  • i did try `-d`'s but it doesn't provide any meaningful information related to the possible cause - just a detailed `npm` lifecycle log – user1935987 Oct 21 '19 at 15:07
  • It couldn't spawn the process. Check permissions of files and folders, specially node_modules. Delete package-lock.json and/or run npm install. If once worked, compare changes in git to see what could had happen, check missing files. Also check RAM available. – Bernardo Dal Corno Oct 22 '19 at 14:58
  • I found [this](https://www.reddit.com/r/node/comments/ch9d2e/i_cannot_run_server_npm_err_code_elifecycle_npm/eur8o37/) Reddit thread that describes an issue similar to yours. A few things to try: changing your port number to something higher than 1024. Do you have `.babelrc` and is it configured/configured properly? Also try `npm cache clean --force`, `delete node_modules`, `npm i`. Also, does the issue persist even when restarting the editor? – Matt Croak Oct 23 '19 at 15:57
  • i tried removing `node_modules`, cleaning cache, etc. i don't use babel. that particular issue was with some imports, but the question, again is about the debugging approach towards such issues when there is no anyhow detailed problem log available – user1935987 Oct 24 '19 at 05:49
  • the thing is there's not a golden rule, we can just go through a checklist, trial and error, scientifically eliminating variables. (a good approach is to start with "bigger" variables) – Bernardo Dal Corno Oct 24 '19 at 16:56
  • 1
    There is no tool for debuting to compilation. They have that in theirs roadmap, but it is yet to be stared to be worked on. – Akxe Oct 24 '19 at 22:56

4 Answers4

4

I solved this problem first delete to package-lock.json write console - npm test
(if there isn't any problem in npm installing probably problem is in server)

  • npm install -g serve
  • npm run build

the problem is solved.. if you want to use your local you can enter

  • serve -s build thats all- Good Luck :)
SelcukBah
  • 39
  • 5
  • probably thats is helped your issue, but my question was morebroad - how to debug this kind of things. and the solution was to use `NODE_DEBUG=*` flag. – user1935987 Dec 18 '19 at 02:49
1

I would start with debugging the compiled script (not minified though) because it removes some intermediate steps between your input and your results. There are multiple methods I tend to debug these issues:

  • First I recommend experimenting with NODE_DEBUG flags like: NODE_DEBUG=module node build/server.js if you suspect the issue is with module loading.
  • You can try node --inspect-brk build/server.js and starting an inspector to step through it (e.g. in Chrome). This is most helpful if your code actually has managed to load, but can sometimes help with custom loaders.
Porcellus
  • 401
  • 1
  • 5
0

As you have stated, the logs are not very detailed, so I would not invest energy into finding out how to debug an undetailed log file, but rather I would find out how to modify my project so that it does some more detailed logging, after each major step, so if it fails at some point, you will see what was successfully executed, what states it ran through and you will not see the logging that you have planned from the point of crashing.

Lajos Arpad
  • 45,912
  • 26
  • 82
  • 148
0

based on @Porcellus answer, was able to fix this issues with NODE_DEBUG=* flag => shown a complete stacktrace of missing modules.

user1935987
  • 2,660
  • 5
  • 37
  • 83