serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

Error when deploy: "no such file or directory .build/.serverless"

Open tomzaku opened this issue 4 years ago • 17 comments

serverless.yml

plugins:
  - serverless-webpack
  - serverless-offline-sqs
  - serverless-offline
  - serverless-plugin-typescript
...
custom:
  serverless-offline-sqs:
    endpoint: http://localhost:4576
    region: ap-southeast-2
functions:
  goalUpdateHandler:
    handler: src/handler.handleGoalUpdate
    reservedConcurrency: 1
    events:
      - sqs:
          queueName: GoalNotificationQueue
          arn:
            Fn::GetAtt:
              - GoalNotificationQueue
              - Arn
          batchSize: 1
...

webpack.config.js

const slsw = require("serverless-webpack");

const babelOptions = {
  plugins: [
    "transform-runtime",
    "dynamic-import-node"
  ],
  presets: [
    "es2015",
    "stage-0"
  ]
};

module.exports = {
  entry: slsw.lib.entries,
  target: "node",
  mode: "development",
  // Generate sourcemaps for proper error messages
  devtool: "source-map",
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  // externals: [nodeExternals({ modulesDir: "../node_modules" })],
  resolve: {
    extensions: [".js", ".jsx", ".json", ".ts", ".tsx"],
  },

  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "babel-loader",
            options: babelOptions
          },
          {
            loader: require.resolve("ts-loader"),
            options: {
              happyPackMode: true,
              // configFile: "../tsconfig.json",

              // disable type checker - we will use it in fork plugin
              transpileOnly: true
            }
          }
        ]
      },
      {
        test: /\.js$/,
        use: [
          {
            loader: "babel-loader",
            options: babelOptions,
          }
        ],
        exclude: /node_modules/
      }
    ]
  }
};

tsconfig.json

{
  "compilerOptions": {
    "module": "esNext",
    "target": "es2017",
    "lib": [
      "es2015",
      "es5",
    ],
    "moduleResolution": "node",
    "noUnusedLocals": false,
    "noUnusedParameters": true,
    "sourceMap": true,
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "resolveJsonModule" : true,
    "typeRoots": ["./node_modules/@types", "../custom_typings", "../node_modules/@types"],
    "esModuleInterop": true,
  },
  "exclude": [
    "node_modules",
    "!node_modules/@types"
  ]
}

Full error

Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Remove long_path/.webpack

  Error --------------------------------------------------

  ENOENT: no such file or directory, stat 'long_path/.build/.serverless'

     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:                     darwin
     Node Version:           11.6.0
     Serverless Version:     1.40.0

tomzaku avatar Jul 17 '19 04:07 tomzaku

I'm experiencing the same issue without a separate build plugin like webpack, babel, etc. This plugin works fine with serverless-offline, but I can't get it to deploy.

nathanchapman avatar Feb 06 '20 00:02 nathanchapman

I have the same issue as @nathanchapman . After sls package, .build directory is deleted and all artifacts move to .serverless folder. But the path mentioned in stack.json is .build/.serverless/<artifcact>. It seems the path is relative to something

rashid301 avatar Feb 06 '20 10:02 rashid301

Workaround (hacky) to fix this was to NOT delete folder .build during packaging. This duplicates artifacts in 2 places. One in .build/.serverless/<artifacts> and another in .serverless/<artifacts>. But it satisfies all package and deploy processes

rashid301 avatar Feb 07 '20 11:02 rashid301

Hi, is there a fix for it? The problem seems to be still there.

 Operating System:          darwin
     Node Version:              14.2.0
     Framework Version:         1.71.1
     Plugin Version:            3.6.12
     SDK Version:               2.3.0
     Components Version:        2.30.10
plugins:
  - serverless-webpack
  - serverless-plugin-typescript
  - serverless-offline

serverless-plugin-typescript: 1.1.9 (downgrade to 1.1.7) does not seem to help.

PavelYaroshchyk avatar May 16 '20 14:05 PavelYaroshchyk

It looks like the problem is the order the following plugins are listed in:

plugins:
  - serverless-webpack
  - serverless-offline-sqs
  - serverless-offline
  - serverless-plugin-typescript

The doc states Add the plugins to your serverless.yml file and make sure that serverless-plugin-typescript precedes serverless-offline as the order is important. The order should be changed to:

- serverless-plugin-typescript
- serverless-offline

melaku-z avatar May 31 '20 18:05 melaku-z

Any update on this?

amouly avatar Aug 26 '20 05:08 amouly

Any fix for this ?

kuda1992 avatar Oct 07 '20 20:10 kuda1992

I hit this problem when I forgot to create a tsconfig.json if that helps anyone. I wasn't using serverless-offline so that was irrelevant for me.

veloware avatar Oct 13 '20 16:10 veloware

Found a fix for the remove the serverless-plugin-typescript plugin from plugins. The serverless-plugin-typescript doesn't work with the serverless-webpack plugin

kuda1992 avatar Oct 13 '20 16:10 kuda1992

Removing the serverless-plugin-typescript works for me. Webpack can compile your typescript files using ts-loader, use that instead and remove the type-script plugin.

shukla2512 avatar Nov 23 '20 11:11 shukla2512

Downgrade the version of my local serverless seems to fix the issue. Went with npm i --save-dev [email protected] previously it was 2.2.37

That said, some of you did have the issue with older serverless versions ... I am not using webpack, but I use serverless-plugin-typescript & serverless-offline
Hope it helps .

GreGosPhaTos avatar Apr 20 '21 16:04 GreGosPhaTos

Just had this issue appearing again today when I updated to 2.37.0. I reverted to 2.35.0 and it fixed it.

serverless.yml plugins

plugins:
  - serverless-plugin-typescript 
  - serverless-offline
  - serverless-aws-documentation
  - serverless-plugin-git-variables
  - serverless-plugin-log-retention

package.json modules versions

    "serverless-plugin-git-variables": "^4.0.0",
    "serverless-plugin-log-retention": "^2.0.0",
    "serverless": "2.35.0",
    "serverless-aws-documentation": "^1.1.0",
    "serverless-offline": "^6.9.0",
    "serverless-plugin-typescript": "^1.1.9",

rojanawi-droople avatar Apr 21 '21 09:04 rojanawi-droople

Same here. I tried with [email protected] and [email protected] and was fixed.

GeroSalas avatar Apr 21 '21 15:04 GeroSalas

Still an issue overhere. No clue what the no such file or directory, stat .build/.serverless means..

rnnyrk avatar Jul 09 '21 11:07 rnnyrk

Having same issue here.

noeleo avatar Sep 05 '21 03:09 noeleo

I am using [email protected], [email protected] and [email protected] and ran into the same issue.

serveless plugins:

plugins: [
        'serverless-dotenv-plugin',
        'serverless-webpack',
        'serverless-webpack-prisma',
        'serverless-plugin-typescript',
        'serverless-offline'
],

It seems that using serverless-plugin-typescript is unnecessary and leading to errors when also using serverless-webpack. (mentioned in this comment) Deleting serverless-plugin-typescript resolved the issue for me.

new serverless plugins:

plugins: [
        'serverless-dotenv-plugin',
        'serverless-webpack',
        'serverless-webpack-prisma',
        'serverless-offline'
],

blochmat avatar Jun 13 '22 04:06 blochmat

Make sure your serverless, serverless-plugin-typescript etc. are in devDependencies and not in dependencies:

"devDependencies": {
    "serverless": "^3.23.0",
    "serverless-offline": "^11.2.3",
    "serverless-plugin-typescript": "^2.1.4",
    "serverless-python-requirements": "^6.0.0",
    "typescript": "^4.8.4"
  }

sazzy4o avatar Nov 06 '22 23:11 sazzy4o