Serverless-next.js: All builds are suddenly failing due to recent changes

Created on 11 May 2020  路  7Comments  路  Source: serverless-nextjs/serverless-next.js

All our building are failing because of the recent changes to lambda-at-edge package.

How do we lock the version? i have locked the version of serverless-next.js in my package.json but it doesn't work.

using sls version 
  error:
  /root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/node_modules/fs-extra/lib/mkdirs/make-dir.js:86
      } catch {
              ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/node_modules/fs-extra/lib/mkdirs/index.js:3:44)

the state file

{
  "components": {
    "myapp": "/root/.serverless/components/registry/npm/[email protected]/node_modules/serverless-next.js"
  }
}

Most recent version i tested that was working was 1.9.8, i need to be able to lock it to that version

Most helpful comment

Hi folks, I'll be looking at why this happens tonight. In the meantime you can pin the version of serverless-next.js:

```

serverless.yml

component: serverless-next.js@{version_here}
...

All 7 comments

Silly me, you can do it in the yml file. but still there is a bug with the new versions.

@SarKurd could you share some context on this? We might be experiencing the same problem, and we haven't fixed it yet.

Hi folks, I'll be looking at why this happens tonight. In the meantime you can pin the version of serverless-next.js:

```

serverless.yml

component: serverless-next.js@{version_here}
...

@marianogappa that's what i did, for now i stick with 1.9.8, i know it's working.

Hi folks, I'll be looking at why this happens tonight. In the meantime you can pin the version of serverless-next.js:

# serverless.yml
component: serverless-next.js@{version_here}
...

@SarKurd @marianogappa Do you mind sharing your serverless.yml? I wasn't able to replicate this issue.
I wonder if there is some input in particular that breaks it.

I'm using only domain and bucketName for now, here the config for both Serverless.yml(pre locking the version) and serverless.js files, it's a little messy but works for us :-D

Also might worth mentioning, i'm deploying through CI

name: portal

myappPortal:
  component: serverless-next.js
  inputs:
    domain:
      - ${env.subdomain}
      - ${env.domain}
    bucketName: ${env.bucketName}

serveless.js

const fs = require('fs');

const yaml = require('js-yaml');
const aws = require('aws-sdk');
const { Component } = require('@serverless/core');

function addPolicy(policy) {
    const doc = yaml.safeLoad(fs.readFileSync('./serverless.yml', 'utf8'));
    doc.myappPortal.inputs = {
        ...doc.myappPortal.inputs,
        policy,
    };

    return doc;
}

const { STAGE } = process.env;

class Deploy extends Component {
    async default() {
        if (STAGE === 'test' || STAGE === 'dev' || STAGE === 'staging' || STAGE === 'prod') {
            // Will load .env-${stage} as environment variables
            require('dotenv').config({ path: `${__dirname}/resources/environments/.env-${STAGE}` });

            const iam = new aws.IAM({ credentials: this.context.credentials.aws });
            const sts = new aws.STS({ credentials: this.context.credentials.aws });

            let policyArn = '';

            try {
                const identity = await sts.getCallerIdentity().promise();

                policyArn = `arn:aws:iam::${identity.Account}:policy/myAppPolicy`;

                const params = {
                    PolicyDocument: JSON.stringify({
                        Version: '2012-10-17',
                        Statement: [
                            {
                                Effect: 'Allow',
                                Action: 'secretsmanager:GetSecretValue',
                                Resource: `*`,
                            },
                            {
                                Effect: 'Allow',
                                Action: [
                                    'logs:CreateLogGroup',
                                    'logs:CreateLogStream',
                                    'logs:PutLogEvents',
                                ],
                                Resource: '*',
                            },
                        ],
                    }),
                    PolicyName: 'myAppPolicy',
                    Description: 'Policy used by my app website',
                    Path: null,
                };

                await iam
                    .createPolicy(params)
                    .promise()
                    .catch(err => {
                        if (err.code !== 'EntityAlreadyExists') {
                            throw new Error(err);
                        }
                    });
            } catch (error) {
                throw new Error(error);
            }

            const doc = addPolicy(policyArn);

            const template = await this.load('@serverless/template', STAGE);

            const output = await template({ template: doc });
            return output;
        }
        this.context.log('No environment defined... Choices are test, dev, staging or prod');
    }

    async remove() {
        this.context.log('Please manually delete the resources');
    }
}

module.exports = Deploy;

@danielcondemarin our issue is well described by this issue's title, but it's actually this one: https://github.com/danielcondemarin/serverless-next.js/issues/397

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AaronMoat picture AaronMoat  路  3Comments

antoinemaz picture antoinemaz  路  7Comments

pedropinheiro75 picture pedropinheiro75  路  7Comments

robsonkades picture robsonkades  路  3Comments

mikdatdogru picture mikdatdogru  路  7Comments