Local offline builds compile and run just fine, but when running serverless deploy builds fail with the following error:
$ yarn deploy:dev
yarn run v1.5.1
$ serverless --stage=dev deploy
Serverless: Bundling with Webpack...
Hash: 553b3b231bc8271d903c
Version: webpack 4.8.2
Time: 86ms
Built at: 2018-05-11 15:54:21
Asset Size Chunks Chunk Names
api/index.js 3.97 KiB 0 api/index
api/index.js.map 465 bytes 0 api/index
Entrypoint api/index = api/index.js api/index.js.map
[0] ./api/index.js 1.26 KiB {0} [built] [failed] [1 error]
ERROR in ./api/index.js
Module build failed: Error: [BABEL] D:\GitHub\mini-movie-db\api\index.js: .definitions is not a valid Plugin property
at D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\validation\plugins.js:54:56
at Array.forEach (<anonymous>)
at validatePluginObject (D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\validation\plugins.js:52:20)
at D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\full.js:215:53
at cachedFunction (D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\caching.js:42:17)
at loadPluginDescriptor (D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\full.js:207:10)
at D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\full.js:64:16
at Array.map (<anonymous>)
at recurseDescriptors (D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\full.js:63:36)
at loadFullConfig (D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\config\full.js:112:6)
at D:\GitHub\mini-movie-db\node_modules\@babel\core\lib\transform.js:28:33
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Error --------------------------------------------------
Webpack compilation error, see above
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.9.4
Serverless Version: 1.27.2
error An unexpected error occurred: "Command failed.
Exit code: 1
Command: C:\\WINDOWS\\system32\\cmd.exe
Arguments: /d /s /c serverless --stage=dev deploy
Directory: D:\\GitHub\\mini-movie-db
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "D:\\GitHub\\mini-movie-db\\yarn-error.log"
.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Previously deployments have worked no problem, there have been no changes to serverless.yml or webpack.api.config.js. (Webpack config file name is set in serverless.yml) Here are the configs:
service: mini-movie-db
frameworkVersion: ">=1.21.0 <2.0.0"
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-west-2
environment:
apikey: ${file(./serverless.env.yml):movieDBApiKey, ""}
stage: ${opt:stage, ""}
plugins:
- serverless-prune-plugin
- serverless-webpack
- serverless-offline
package:
individually: true
custom:
serverless-offline:
port: 1337
prune:
automatic: true
number: 3
webpack:
includeModules: true
packager: 'yarn'
webpackConfig: 'webpack.api.config.js'
functions:
api:
handler: api/index.graphqlHandler
events:
- http:
path: "{proxy+}"
method: any
cors: true
playground:
handler: api/playground.playgroundHandler
events:
- http:
path: "/playground"
method: get
cors: true
const { join } = require(`path`)
const slsw = require(`serverless-webpack`) // https://github.com/serverless-heaven/serverless-webpack
const nodeExternals = require(`webpack-node-externals`) // https://github.com/liady/webpack-node-externals
module.exports = {
mode: slsw.lib.webpack.isLocal ? `development` : `production`,
entry: slsw.lib.entries,
target: `node`,
externals: [nodeExternals()],
devtool: `nosources-source-map`,
output: {
libraryTarget: `commonjs`,
path: join(__dirname, `.webpack`),
filename: `[name].js`,
sourceMapFilename: `[file].map`
},
stats: {
colors: true,
reasons: false,
chunks: false
},
performance: {
hints: false
},
optimization: {
minimize: false
},
module: {
rules: [
{
test: /\.js$/,
loader: `babel-loader`,
exclude: /node_modules/,
options: {
babelrc: false,
plugins: [require(`@babel/plugin-transform-runtime`)],
presets: [
[require(`@babel/preset-env`), { targets: { node: `8.10` } }],
[require(`@babel/preset-stage-0`), { decoratorsLegacy: true }]
]
}
},
{ test: /\.(graphql|gql)$/, exclude: /node_modules/, loader: `graphql-tag/loader` }
]
}
}
Here's the repo for the project if you would like to try and reproduce the error yourself:
https://github.com/Saeris/mini-movie-db/tree/develop
I know the error output says babel is throwing the error, but that doesn't appear to be the source of the issue since webpack and babel appear to work just fine when running offline.
Hi @Saeris ,
Previously deployments have worked no problem, there have been no changes
Did you do any updated on the build components or the dependencies? If the deployment worked before, but ceased to do so, this hints to something that has changed.
We should try to find out, what triggered this change in behavior.
BTW, just out of curiosity: Is there a reason why you used backticks in your webpack.config.js instead of standard quotes?
As a general rule of thumb, I use backticks for all strings, because there's no performance downside that I know of and it makes it simpler to do string concatenation anywhere at a later point.
Where dependencies are concerned, at least a dozen have been upgraded, I don't know which might cause this error to happen. It doesn't make sense to me that I can build webpack bundles just fine and run them locally without error, but then deployments specifically end up failing. As far as configuration is concerned, there have been no changes.
I could try creating a branch from the last working commit and try running it with serverless-webpack upgraded specifically. Right now though it's almost 4am and I need to get some sleep.
Recently got back to debugging this issue again. Wanted to share some updates:
I get a different error when I remove the option to package individually, here's what I get with that configuration:
$ yarn deploy
yarn run v1.6.0
$ yarn deploy:dev
$ cross-env SLS_DEBUG=TRUE serverless --stage=dev deploy
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 config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Sentry: Setting release version to ""...
Serverless: Invoke webpack:validate
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Hash: b8447c9ce1eb655a0ae2
Version: webpack 4.16.4
Time: 499ms
Built at: 2018-08-04 22:55:07
Asset Size Chunks Chunk Names
src/index.js 127 KiB 0 [emitted] src/index
src/index.js.map 58.5 KiB 0 [emitted] src/index
Entrypoint src/index = src/index.js src/index.js.map
[0] external "@babel/runtime/helpers/interopRequireDefault" 42 bytes {0} [built]
[1] external "@babel/runtime/helpers/interopRequireWildcard" 42 bytes {0} [built]
[4] external "winston" 42 bytes {0} [built]
[6] external "apollo-server-lambda" 42 bytes {0} [built]
[7] external "raven" 42 bytes {0} [built]
[8] ./src/index.js 1.27 KiB {0} [built]
[9] external "serverless-sentry-lib" 42 bytes {0} [built]
[10] external "apollo-server-cache-redis" 42 bytes {0} [built]
[11] ./src/schema.js 1.34 KiB {0} [built]
[13] ./src/types/index.js 3.72 KiB {0} [built]
[40] ./src/types/inputs/index.js 370 bytes {0} [built]
[42] ./src/types/unions/index.js 374 bytes {0} [built]
[44] ./src/resolvers/index.js 2.01 KiB {0} [built]
[66] ./src/sources/index.js 303 bytes {0} [built]
[70] ./src/logger.js 1.14 KiB {0} [built]
+ 59 hidden modules
Serverless: Invoke webpack:package
Serverless: WARNING: Could not determine version of module winston-transport
Serverless: WARNING: Could not determine version of module triple-beam
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: @babel/runtime@^7.0.0-beta.56, winston@^3.0.0, apollo-server-lambda@^2.0.0, [email protected], rave
n@^2.6.3, serverless-sentry-lib@^1.1.1, apollo-server-cache-redis@^0.1.0, graphql-tools@^3.0.0, apollo-datasource-rest@^0.1.1, winston
-transport, triple-beam
Error --------------------------------------------------
yarn.cmd install --frozen-lockfile --non-interactive failed with code 1
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
yarn.cmd install --frozen-lockfile --non-interactive failed with code 1
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
at ChildProcess.child.on.exitCode (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\utils.js:92:16)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
From previous event:
at Object.spawnProcess (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\utils.js:73:10)
at Function.install (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\packagers\yarn.js:118:18)
at BbPromise.fromCallback.then.then (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\packExternalModules.j
s:288:27)
at fn.apply.then.r (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\universalify\index.js:23:46)
at <anonymous>
From previous event:
at packager.getProdDependencies.then.dependencyGraph (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\pack
ExternalModules.js:285:10)
From previous event:
at BbPromise.try.then.packager (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\packExternalModules.js:222
:8)
From previous event:
at ServerlessWebpack.packExternalModules (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\lib\packExternalModu
les.js:209:6)
From previous event:
at Object.webpack:package:packExternalModules [as hook] (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\index
.js:165:10)
at BbPromise.reduce (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:55)
From previous event:
at PluginManager.invoke (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:22)
at PluginManager.spawn (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:408:17)
at ServerlessWebpack.BbPromise.bind.then.then.then (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\index.js:1
02:51)
From previous event:
at Object.before:package:createDeploymentArtifacts [as hook] (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless-webpack\
index.js:102:10)
at BbPromise.reduce (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:55)
From previous event:
at PluginManager.invoke (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:22)
at PluginManager.spawn (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:408:17)
at Deploy.BbPromise.bind.then.then (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\plugins\deploy\deploy.js:123:5
0)
From previous event:
at Object.before:deploy:deploy [as hook] (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\plugins\deploy\deploy.js
:113:10)
at BbPromise.reduce (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:55)
From previous event:
at PluginManager.invoke (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:390:22)
at PluginManager.run (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\classes\PluginManager.js:421:17)
at variables.populateService.then.then (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\Serverless.js:157:33)
at runCallback (timers.js:789:20)
at tryOnImmediate (timers.js:751:5)
at processImmediate [as _immediateCallback] (timers.js:722:5)
From previous event:
at Serverless.run (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\lib\Serverless.js:144:8)
at serverless.init.then (D:\GitHub\Mini-Movie-DB-API-Example\node_modules\serverless\bin\serverless:43:50)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 8.9.4
Serverless Version: 1.29.2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
If I also remove the option to use Yarn as my packager, deployment seems to proceed past everything webpack related and on to the cloudformation template validation. I've got a separate issue there to work out (I'm trying to figure out how to provision the resources for a redis cache as well). Seeing as others have brought up issues regarding package individually and packager: "yarn" too, I thought it would be worth noting here.
Hi @Saeris . Yarn is more strict (and thus safer) than npm. It will not proceed if it detects that a module that is to be installed has to be updated to a different version than stated in your lock file or if modules would be silently installed.
Can you check if you are using any modules that are not mentioned in your package.json or that are somehow not fixed to a version range?
These messages also hint to such a problem
Serverless: WARNING: Could not determine version of module winston-transport
Serverless: WARNING: Could not determine version of module triple-beam
For both of those warnings it's because I'm importing packages that were installed as sub-dependencies of winston, so I could add those to my package.json for them to explicitly have a version.
I still ran into problems without these two packages causing warnings however. If from what you're saying is true, then it may be because I'm using ESLint 4.x instead of 5.x, which is the only dependency that yarn outdated was telling me there's an upgrade for. Haven't attempted to upgrade yet in my projects because the initial release of 5.x broke a lot of things.
@Saeris Just add the versions for winston-transport and triple-beam as suggested by @HyperBrain and then do a yarn install
Deploying after that should work.
I have the same issue with dependencies required by the package I'm importing.
I'm having a similar issue where the build works locally, but it fails on CI with no helpful error message when it runs the npm prune command in the build directory:
Local output:
...
Serverless: Copy modules: /.webpack/service [11188 ms]
Serverless: Prune: /.webpack/service [20327 ms]
Serverless: Run scripts: /.webpack/service [30481 ms]
...
CI output:
...
Serverless: Copy modules: /opt/atlassian/pipelines/agent/build/.webpack/service [6235 ms]
Error --------------------------------------------------
Error: npm prune failed with code 254
at ChildProcess.child.on.exitCode (/opt/atlassian/pipelines/agent/build/node_modules/serverless-webpack/lib/utils.js:91:16)
at ChildProcess.emit (events.js:189:13)
at ChildProcess.EventEmitter.emit (domain.js:441:20)
at maybeClose (internal/child_process.js:970:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
UPDATE: After ~5 hours of investigation, I found out it was an npm bug 🤦♂️ and fixed it by upgrading npm on my CI server from 6.4.1 to the most recent version (6.14.5).
UPDATE: After ~5 hours of investigation, I found out it was an npm bug 🤦♂️ and fixed it by upgrading npm on my CI server from 6.4.1 to the most recent version (6.14.5).
@ardalann How did you determine it was an npm bug? I am facing a similar issue with npm 6.13.4. I will try the latest version but the problem is it's a super transient bug that only happens on some builds.
@nikolas-x I believe it was an npm bug because once I upgraded npm on my CI server the error did not occur anymore.