This repository has been archived by the owner. It is now read-only.

Webpack fails only when run through `npm run` command #12931

Closed
deevus opened this Issue Jun 2, 2016 · 17 comments

Comments

Projects
None yet
8 participants
@deevus

deevus commented Jun 2, 2016

Ok I've been pulling my hair out on this issue all day thinking that it was something I have done incorrectly (this could still be the case). If I run webpack through a package.json script, it fails. I discovered that running it straight from cmd works fine, as odd as that might sound.

Please note that this is running on Azure Websites (kudu) The command works fine on my local machine.

Output when run using npm run:

PS D:\home\site\wwwroot> npm run dev:build

> statsone-team@0.1.0 dev:build D:\home\site\wwwroot
> npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail


> statsone-team@0.1.0 tsc:webpack D:\home\site\wwwroot
> tsc ./config/webpack.config.ts ./typings/index.d.ts ./node_modules/typescript/lib/lib.es6.d.ts

[webpack-validator] Config is valid.
ts-loader: Using typescript@1.8.10 and D:\home\site\wwwroot\lib\components\tsconfig.json
ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' ./100.78.96.42/volume-1-default/93ed3614bdcf632e2c04/7727d4897b44417fbda402e033601851/site/wwwroot/node_modules/webpack/buildin/module.js in D:\home\site\wwwroot\lib\components
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\lib\Compilation.js:229:38
    at onDoneResolving (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\lib\NormalModuleFactory.js:29:20)
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\lib\NormalModuleFactory.js:85:20
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:726:13
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:52:16
    at done (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:241:17)
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:44:16
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:723:17
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\async\lib\async.js:167:37
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:24:19
    at onResolved (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\Resolver.js:38:18)
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\Resolver.js:127:10
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\Resolver.js:110:4)
    at loggingCallbackWrapper (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\createInnerCallback.js:21:19)
    at \\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\tapable\lib\Tapable.js:134:6
    at Tapable.<anonymous> (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\DirectoryDescriptionFilePlugin.js:24:12)
    at Storage.finished (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:38:16)
    at ReadFileContext.callback (\\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\graceful-fs\graceful-fs.js:78:16)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:359:13)
resolve file
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js doesn't exist
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js.ts doesn't exist
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js.tsx doesn't exist
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js.jsx doesn't exist
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js.js doesn't exist
resolve directory
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js doesn't exist (directory default file)
  D:\home\site\wwwroot\lib\components\100.78.96.42\volume-1-default\93ed3614bdcf632e2c04\7727d4897b44417fbda402e033601851\site\wwwroot\node_modules\webpack\buildin\module.js\package.json doesn't exist (directory description file)

npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\6.1.0\\node.exe" "D:\\Program Files (x86)\\npm\\3.8.6\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev:build"
npm ERR! node v6.1.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! statsone-team@0.1.0 dev:build: `npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the statsone-team@0.1.0 dev:build script 'npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the statsone-team package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs statsone-team
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls statsone-team
npm ERR! There is likely additional logging output above.
PS D:\home\site\wwwroot> 
npm ERR! Please include the following file with any support request:
npm ERR!     D:\home\site\wwwroot\npm-debug.log

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ 'D:\\Program Files (x86)\\nodejs\\6.1.0\\node.exe',
1 verbose cli   'D:\\Program Files (x86)\\npm\\3.8.6\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev:build' ]
2 info using npm@3.8.6
3 info using node@v6.1.0
4 verbose run-script [ 'predev:build', 'dev:build', 'postdev:build' ]
5 info lifecycle statsone-team@0.1.0~predev:build: statsone-team@0.1.0
6 silly lifecycle statsone-team@0.1.0~predev:build: no script for predev:build, continuing
7 info lifecycle statsone-team@0.1.0~dev:build: statsone-team@0.1.0
8 verbose lifecycle statsone-team@0.1.0~dev:build: unsafe-perm in lifecycle true
9 verbose lifecycle statsone-team@0.1.0~dev:build: PATH: C:\Program Files (x86)\npm\3.8.6\node_modules\npm\bin\node-gyp-bin;D:\home\site\wwwroot\node_modules\.bin;D:\Program Files (x86)\nodejs\6.1.0;C:\Program Files (x86)\SiteExtensions\Kudu\55.50526.2249\bin\Scripts;D:\Program Files (x86)\MSBuild\14.0\Bin;D:\Program Files (x86)\Git\cmd;D:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow;D:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn;D:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0;D:\Program Files (x86)\Git\bin;D:\Program Files (x86)\Git\usr\bin;D:\Program Files (x86)\npm\3.8.6;C:\DWASFiles\Sites\#1statsone-team__f009\AppData\npm;D:\Program Files (x86)\bower\1.3.12;D:\Program Files (x86)\grunt\0.1.13;D:\Program Files (x86)\gulp\3.9.0.1;D:\home\site\deployments\tools;D:\Program Files (x86)\nodejs\6.1.0;D:\Windows\system32;D:\Windows;D:\Windows\System32\Wbem;D:\Windows\System32\WindowsPowerShell\v1.0\;D:\Program Files\Microsoft Network Monitor 3\;D:\Users\Administrator\AppData\Roaming\npm;D:\Program Files (x86)\nodejs\;d:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;;E:\base\x64;E:\base\x86;;D:\Packages\GuestAgent\GuestAgent\LegacyRuntime\x64;D:\Packages\GuestAgent\GuestAgent\LegacyRuntime\x86;;D:\Program Files (x86)\Mercurial\;D:\Program Files (x86)\dotnet;D:\Program Files (x86)\PHP\v5.4;D:\Python27;
10 verbose lifecycle statsone-team@0.1.0~dev:build: CWD: D:\home\site\wwwroot
11 silly lifecycle statsone-team@0.1.0~dev:build: Args: [ '/d /s /c',
11 silly lifecycle   'npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail' ]
12 silly lifecycle statsone-team@0.1.0~dev:build: Returned: code: 1  signal: null
13 info lifecycle statsone-team@0.1.0~dev:build: Failed to exec dev:build script
14 verbose stack Error: statsone-team@0.1.0 dev:build: `npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Program Files (x86)\npm\3.8.6\node_modules\npm\lib\utils\lifecycle.js:239:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (C:\Program Files (x86)\npm\3.8.6\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:850:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid statsone-team@0.1.0
16 verbose cwd D:\home\site\wwwroot
17 error Windows_NT 6.2.9200
18 error argv "D:\\Program Files (x86)\\nodejs\\6.1.0\\node.exe" "D:\\Program Files (x86)\\npm\\3.8.6\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev:build"
19 error node v6.1.0
20 error npm  v3.8.6
21 error code ELIFECYCLE
22 error statsone-team@0.1.0 dev:build: `npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail`
22 error Exit status 1
23 error Failed at the statsone-team@0.1.0 dev:build script 'npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the statsone-team package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     npm run tsc:webpack && webpack --display-error-details --config ./config/webpack.config.js --bail
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs statsone-team
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls statsone-team
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

Output when run straight from the Powershell console on Kudu:

PS D:\home\site\wwwroot> webpack --display-error-details --config ./config/webpack.config.js --bail
[webpack-validator] Config is valid.
ts-loader: Using typescript@1.8.10 and D:\home\site\wwwroot\tsconfig.json
ts-loader: Using typescript@1.8.10 and D:\home\site\wwwroot\lib\components\tsconfig.json
Hash: edc018fe2e4deb523737
Version: webpack 1.13.1
Time: 115736ms
                                 Asset       Size  Chunks             Chunk Names
                           favicon.ico    5.43 kB          [emitted]  
  f4769f9bdb7466be65088239c12046d1.eot    20.1 kB          [emitted]  
448c34a56d699c29117adc64c43affeb.woff2      18 kB          [emitted]  
 fa2772327f55d8198301fdb8bcfc8158.woff    23.4 kB          [emitted]  
  e18bbf611f2a2e43afc071aa2f4e1512.ttf    45.4 kB          [emitted]  
  img/glyphicons-halflings-regular.svg     109 kB          [emitted]  
                             client.js    10.6 MB       0  [emitted]  client
                              style.js    1.41 MB       1  [emitted]  style
                            index.html  241 bytes          [emitted]  
   [0] multi style 40 bytes {1} [built]
   [0] multi client 40 bytes {0} [built]
    + 1173 hidden modules
Child html-webpack-plugin for "index.html":
        + 3 hidden modules
@sahat

This comment has been minimized.

sahat commented Jun 2, 2016

Running into a similar issue Module not found: Error: Cannot resolve 'file' or 'directory' with Webpack and Azure. https://twitter.com/EvNowAndForever/status/738436408545845249

@deevus

This comment has been minimized.

deevus commented Jun 3, 2016

@sahat Seems like the same issue to me

@deevus

This comment has been minimized.

deevus commented Jun 3, 2016

It seems like the issue might be related to npm using a local copy of webpack. See projectkudu/kudu#2032

@sahat

This comment has been minimized.

sahat commented Jun 3, 2016

@deevus I have spent more than 3 days trying to debug this issue to no avail, but in the end I removed lodash and moment dependencies and replaced them with my own vanilla JS functions in the app.

Let me know if a global webpack package solves the issue so I can get a closure with this bug.

@deevus

This comment has been minimized.

deevus commented Jun 3, 2016

@sahat Tell me about it! Management is breathing down my neck wanting to test a new application but I've been stuck with this issue. I really don't want to push the built bundles to Azure.

@deevus

This comment has been minimized.

deevus commented Jun 3, 2016

@sahat Using a globally installed webpack worked. At this stage it's looking like npm is not the culprit, so I'll close this one for now. I think it's likely an issue with Kudu or the Azure environment.

@deevus deevus closed this Jun 3, 2016

@sahat

This comment has been minimized.

sahat commented Jun 3, 2016

@deevus Thanks! I will update the deployment script to use global webpack as you suggested.

@zygimantas

This comment has been minimized.

zygimantas commented Jul 4, 2016

@deevus I suspect that the problem is inside webpack's enhanced.resolve or memory-fs dependencies and I am having same (or very closely related) issues.

Here is a gist of callstack I've got: https://gist.githubusercontent.com/zygimantas/6d5fcb15547e84f5773f7b6226734737/raw/f37bd1a1ee46018413aa4cb24fc6187732314838/output.txt

And here is a not very well formulated stackoverflow question: http://stackoverflow.com/questions/38173996/azure-and-node-js-dirname

I tried debugging the normalize.js file and it was stuck in recursion with path /package.json

@deevus

This comment has been minimized.

deevus commented Jul 4, 2016

@zygimantas Should we create an issue over there?

@zygimantas

This comment has been minimized.

zygimantas commented Jul 4, 2016

@deevus Sure, I have updated my comment with more details

@zygimantas

This comment has been minimized.

zygimantas commented Jul 4, 2016

By the way, to get the same error and get the path resolved, you can add context: __dirname to webpack.config.js. Otherwise, as you mentioned, it fails to resolve.

@deevus

This comment has been minimized.

deevus commented Jul 4, 2016

@zygimantas Are you saying setting context: __dirname resolves the issue?

@tinchou

This comment has been minimized.

tinchou commented Jul 27, 2016

@deevus I just tried and it doesn't fix it. Maybe @zygimantas tried to say it triggers it. (I already had the issue and landed here trying to find a solution).

EDIT: There's good info in the SO question @zygimantas posted http://stackoverflow.com/questions/38173996/azure-and-node-js-dirname. Downgrading to 5.9.0 worked for me.

@tomascharad

This comment has been minimized.

tomascharad commented Oct 26, 2016

Hi guys, I'm having the same problem.

For me it triggers when I change the devtool from eval to source-map

@michelalbers

This comment has been minimized.

michelalbers commented Jan 14, 2017

I just added -f to the npm run command. It seems webpack outputs to stderr for some reason and npm interprets that as exit code 2. Weird.

@luchillo17

This comment has been minimized.

luchillo17 commented Jan 27, 2017

In my case i was lacking the ts-node package in my package.json file (i mean install it), i have it in local so webpack was able to parse my config made in typescript, but i didn't had it in local, so i wasn't able to pass through the config parse process.

@arivera12

This comment has been minimized.

arivera12 commented Jun 7, 2018

Sorry for replying on a closed issue. I run into the same error. After using -f I had a permission error on the build.js file. I deleted the dist folder re run the build cmd and everything started running normally. Hope this helps someone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.