[serverless framework V4] Transpile and Build not work

I’m currently trying to use the built-in build feature in V4 to transpile and bundle src/*.ts files.

build:
  esbuild:
    # Enable bundling
    bundle: true
    # Disable function code minification
    minify: false
serverless deploy --stage dev --debug

Here’s the error message:

s:cli-error-handler: ENOENT: no such file or directory, open '/Users/kenshin/Projects/bs-lambda-sls/bs-sls3/.serverless/build/package.json' (ENOENT)
Error: ENOENT: no such file or directory, open '/Users/kenshin/Projects/bs-lambda-sls/bs-sls3/.serverless/build/package.json'

✖ ENOENT: no such file or directory, open '/Users/kenshin/Projects/bs-lambda-sls/bs-sls3/.serverless/build/package.json'
Error: ENOENT: no such file or directory, open '/Users/kenshin/Projects/bs-lambda-sls/bs-sls3/.serverless/build/package.json'

For help, try the following:
  • Run the command again with the "--debug" option
  • Run "serverless support"
  • Review the docs: https://www.serverless.com/framework/docs/

The ‘build’ directory is not being created under .serverless at all. What configuration should I make to resolve this?

Your assistance would be greatly appreciated.

1 Like

Did you ever get this solved?

I’ve been getting this intermittently, no all the time. I was getting it then changed something and it went away. unfortunately what I thought it was, it wasn’t :frowning:

I’m pretty sure it’s got something to do with the build failing or something. it’s not that the package.json isn’t there, it is, it just gets cleaned up with the failure and looks like no errors really being reported.

I’ll have to keep playing around to see if I can get it to run again, then see what I did.

If anyone has any info on this it would be really appreciated.
v4.4.7
with custom esbuild.config.js

I’m going to raise a bug for this. If I remove the configFile, it builds fine. I thought maybe it was something to do with our specific esbuild config.

but I have run it with the vanilla example in the docs

module.exports = (serverless) => {
return {
external: [‘@aws-sdk/client-s3’]
}
}

and it still has the issue

s:core:meta: saving meta record to global .serverless directory.
s:cli-error-handler: Error: ENOENT: no such file or directory, open ‘/Users/fridaystreet/dev/aleign-graphql-backend/.serverless/build/package.json’
at async open (node:internal/fs/promises:639:25)
at async writeFile (node:internal/fs/promises:1212:14)
at async Esbuild._preparePackageJson (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/plugins/esbuild/index.js:901:5)
at async before:package:createDeploymentArtifacts (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/plugins/esbuild/index.js:45:11)
at async PluginManager.runHooks (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:680:9)
at async PluginManager.invoke (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:718:9)
at async PluginManager.run (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:768:7)
at async Serverless.run (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/serverless.js:221:5)
at async runFramework (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/lib/runners/framework.js:291:5)
at async route (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/lib/router.js:221:10)
at async Object.run2 (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/index.js:45:3)
at async run3 (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/bin/sf-core.js:33:3)

:heavy_multiplication_x: Error: ENOENT: no such file or directory, open ‘/Users/fridaystreet/dev/aleign-graphql-backend/.serverless/build/package.json’
at async open (node:internal/fs/promises:639:25)
at async writeFile (node:internal/fs/promises:1212:14)
at async Esbuild._preparePackageJson (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/plugins/esbuild/index.js:901:5)
at async before:package:createDeploymentArtifacts (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/plugins/esbuild/index.js:45:11)
at async PluginManager.runHooks (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:680:9)
at async PluginManager.invoke (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:718:9)
at async PluginManager.run (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/classes/plugin-manager.js:768:7)
at async Serverless.run (/Users/fridaystreet/.serverless/releases/4.4.7/serverless/lib/serverless.js:221:5)
at async runFramework (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/lib/runners/framework.js:291:5)
at async route (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/lib/router.js:221:10)
at async Object.run2 (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/src/index.js:45:3)
at async run3 (/Users/fridaystreet/.serverless/releases/4.4.7/sf-core/bin/sf-core.js:33:3)

logged an issue here, but in the meantime, found the workaorund to be, just disable sls esbuild, run esbuild manually, then setup the package patterns in sls to only include you build files

eg something like

build:
  esbuild: false
package:
  patterns:
    - '!**'
    - 'node_modules/@abraham/**/*'
    - 'dist/**'
    - 'package.json'