简体   繁体   中英

Running Node.js app from start script results in “Cannot find module” error

I just put together my first Express app. I can run the server without issue using node server.js but when I attempt to use a start script (which it seems Heroku needs), I get the following error. Unlike similar questions where the module in question appears to be a package, I cannot see what "module" is being referred to. I have tried deleting npm and npm-cache , node-modules , etc.

OS: Windows 8.1
Node: v8.11.3
NPM: v5.6.0

Error: Cannot find module 'C:\Users\Derek\Documents\Cloud\Projects\2018-2019\NodeTest\example-server\server.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! example-server@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the example-server@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Derek\AppData\Roaming\npm-cache\_logs\2018-09-09T07_27_10_7
14Z-debug.log

My package.json :

{
  "name": "example-server",
  "version": "1.0.0",
  "main": "src/server.js",
  "private": true,
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "dotenv": "^6.0.0",
    "express": "^4.16.3",
    "firebase-admin": "^6.0.0",
    "pg": "^7.4.3"
  }
}

Project structure:

example-server   
└───node_modules
└───src
│   └───server.js
│
└───package.json

And here is the output from the log file:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Development\\nodejs\\node.exe',
1 verbose cli   'C:\\Development\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle example-server@1.0.0~prestart: example-server@1.0.0
6 info lifecycle example-server@1.0.0~start: example-server@1.0.0
7 verbose lifecycle example-server@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle example-server@1.0.0~start: PATH: C:\Development\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Derek\Documents\Cloud\Projects\2018-2019\NodeTest\example-server\node_modules\.bin;C:\Development\PostgreSQL\10\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\ImageMagick-7.0.7-Q16;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;C:\Development\Python3\;C:\Development\Python3\Scripts;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Development\cURL\bin;C:\Development\Python27\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\TortoiseSVN\bin;C:\Development\cygwin64\bin;C:\Development\MinGW\bin;C:\Development\ChucK\/bin;C:\Program Files\Git LFS;C:\Development\ANDROID_SDK;C:\Development\ANDROID_SDK\tools;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\Skype\Phone\;C:\Development\Yarn\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Amazon\AWSCLI\;C:\Development\nodejs\;C:\Program Files\heroku\bin;C:\Users\Derek\AppData\Local\GitHub\PortableGit_69bd5e6f85e4842f07db71c9618a621154c52254\bin;C:\Development\flutter\bin;C:\Program Files\ImageMagick-7.0.7-Q16;C:\Development\ffmpeg-3.4.1-win64-static\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;C:\Development\Python3\Scripts\;C:\Development\Python3\;C:\Development\RailsInstaller\Ruby2.2.0\bin;C:\Development\ANDROID_SDK\platform-tools\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Development\cURL\bin;C:\Users\Derek\AppData\Roaming\npm
9 verbose lifecycle example-server@1.0.0~start: CWD: C:\Users\Derek\Documents\Cloud\Projects\2018-2019\NodeTest\example-server
10 silly lifecycle example-server@1.0.0~start: Args: [ '/d /s /c', 'node server.js' ]
11 silly lifecycle example-server@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle example-server@1.0.0~start: Failed to exec start script
13 verbose stack Error: example-server@1.0.0 start: `node server.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Development\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Development\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid example-server@1.0.0
15 verbose cwd C:\Users\Derek\Documents\Cloud\Projects\2018-2019\NodeTest\example-server\src
16 verbose Windows_NT 6.3.9600
17 verbose argv "C:\\Development\\nodejs\\node.exe" "C:\\Development\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v8.11.3
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error example-server@1.0.0 start: `node server.js`
22 error Exit status 1
23 error Failed at the example-server@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I don't mean to just dump my errors here but I'm quite new to Node and have spent several hours Googling to no avail.

Your file path for server.js is wrong in "start": "node server.js"

try: "start": "node src/server.js"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM