Closed jake-lambert-volusion closed 6 years ago
Hi @jake-lambert-volusion . This is strange. We also use private scoped packages that need an authorization from .npmrc
and it works correctly. We use Bamboo on a separate server for the deployment.
I think you're right that npm can somehow not find the .npmrc
file. Is the user that executes the initial npm install
the same that then runs the serverless deploy
? I ask, because if you don't use a global .npmrc
it will be fetched from the user's home directory.
BTW: Can you try to let serverless be executed with SLS_DEBUG="*" serverless ... --verbose
to get the maximum log out of it?
@HyperBrain Thanks so much for the quick reply - very glad to hear that what we are trying to do can work.
It is the same user running npm install and serverless deploy (unless there is some weird codeship magic going on).
More debug output is below. Two additional details perhaps worth noting:
.npmrc
is being read but our token is undefined at that point so npm install fails?[15:04:12] Starting 'deploy:serverless:int'...
[15:04:12] Deploying serverless project from path /home/rof/src/github.com/[REMOVED]
[15:04:13] Processing command deploy with options: { stage: 'int',
environment: 'integration'
verbose: true }
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command prune
Serverless: Load command webpack
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Invoke webpack:validate
Serverless: Using configuration:
{
"includeModules": true,
"webpackConfig": "webpack.config.js",
"packager": "npm",
"packagerOptions": {},
"packExternalModulesMaxBuffer": 204800
}
Serverless: Removing /home/rof/src/github.com/[REMOVED]/.webpack
Serverless: Using multi-compile (individual packaging)
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Time: 814ms
Built at: 2018-04-27 15:04:20
Asset Size Chunks Chunk Names
src/addOrUpdateRedirects.js 1.38 KiB 0 [emitted] src/addOrUpdateRedirects
Entrypoint src/addOrUpdateRedirects = src/addOrUpdateRedirects.js
[0] external "@[REMOVED PRIVATE PACKAGE]" 42 bytes {0} [built]
[1] external "csv-parse/lib/sync" 42 bytes {0} [built]
[2] ./src/addOrUpdateRedirects.js 1.71 KiB {0} [built]
Serverless: Invoke webpack:package
Serverless: Fetch dependency graph from /home/rof/src/github.com/[REMOVED]/package.json
(node:5769) DeprecationWarning: Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: [REMOVED PRIVATE PACKAGE], csv-parse@^2.2.0
[15:04:31] 'deploy:serverless:int' errored after 18 s
[15:04:31] Error: Command failed: npm install
Is this possible a problem source?
Maybe. To eliminate that, you could setup a very small project that only uses serverless-webpack
. The project should reference the private package in the dependencies and the sample code should use it somewhere. Then try to have this project built. You don't need to do a full deploy on your CI/CD. Just a serverless package
instead of deploy should be sufficient, as it runs through the whole packaging.
A further hint for a possible interference of the two plugin is the deploy:serverless:int
log line. This is not emitted by serverless-webpack, but maybe from the gulp plugin.
our .npmrc file is reading a token from an environment variable
serverless-webpack uses child_process.exec()
and since version 5.1.2 child_process.spawn
to execute npm. The environment is not altered and so the child process should inherit the full environment from the running serverless process. Of course I cannot state anything about the gulp plugin because we do not use it.
deploy:serverless:int
is our gulp task which calls serverless-gulp.exec.
I will try your suggestion and report back either way.
Per https://github.com/npm/npm/issues/7995#issuecomment-175915766, adding echo "//registry.npmjs.org/:_authToken=\${NPM_AUTH_TOKEN}" > ~/.npmrc
before sls package
resolved it, so does indeed seem to be some kind of path resolution issue with my codeship setup and/or webpack config.
@jake-lambert-volusion Nice find 👍 . Good to know that you were able to get it working.
Just experienced a similar issue using a private package from GitHub Package Registry. The local .npmrc did not work, but copying it to ~/.npmrc allowed serverless-webpack to succeed
If using yarn, specifying it as the packager is an alternative option. Please see: https://github.com/serverless-heaven/serverless-webpack/issues/71#issuecomment-553232334
This is a Bug Report / Question
Description
What went wrong? I am getting
Error: Command failed: npm install
just afterPacking external modules:
which includes a package from a private prefix (i.e. requires an auth token for the registry in.npmrc
). I am able to run serverless package locally with no problem so maybe it is something particular to Codeship, however the initialnpm install
in our build process works fine, so I suspect either the.npmrc
file isn't being seeing when serverless-webpack doesnpm install
.What did you expect should have happened? A successful build.
What was the config you used?
module.exports = { entry: slsw.lib.entries, target: "node", mode: slsw.lib.webpack.isLocal ? "development" : "production", externals: [nodeExternals()], module: { rules: [ { test: /.js$/, exclude: /node_modules/, use: [ { loader: "babel-loader" } ] } ] } };
(node:5950) DeprecationWarning: Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead Serverless: Package lock found - Using locked versions Serverless: Packing external modules: [REMOVED - private scoped package], csv-parse@^2.2.0 [06:01:03] 'deploy:serverless:int' errored after 13 s [06:01:03] Error: Command failed: npm install npm ERR! code E404 npm ERR! 404 Not Found: [REMOVED]@https://registry.npmjs.org/[REMOVED]
npm ERR! A complete log of this run can be found in: npm ERR! /home/rof/.npm/_logs/2018-04-27T06_01_03_547Z-debug.log
at ChildProcess.exithandler (child_process.js:273:12) at ChildProcess.emit (events.js:180:13) at ChildProcess.emit (domain.js:440:23) at maybeClose (internal/child_process.js:936:16) at Socket.stream.socket.on (internal/child_process.js:353:11) at Socket.emit (events.js:180:13) at Socket.emit (domain.js:440:23) at Pipe._handle.close [as _onclose] (net.js:541:12)