Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT: no such file or directory, scandir '.open-next/...' #401

Closed
Bathilde opened this issue Apr 4, 2024 · 19 comments
Closed

ENOENT: no such file or directory, scandir '.open-next/...' #401

Bathilde opened this issue Apr 4, 2024 · 19 comments

Comments

@Bathilde
Copy link

Bathilde commented Apr 4, 2024

I have a nextJS application that was working well until yesterday.

Now during my test deployment phase (npx sst deploy --stage test), I have the ENOENT error, where '.open-next/assets' is missing. This is only happening when I tried to build from gitlab, and if I try to run the command from my mac, it is perfectly working.

Note that I had a build 2h before perfectly working, and I relaunched it, it is now failing....with a similar error:
ENOENT: no such file or directory, open '.next/routes-manifest.json'

What could be the reason ? Is there any cache I could remove to retry ?

Thank you.

@khuezy
Copy link
Collaborator

khuezy commented Apr 4, 2024

First thing I'd check is the OS and runtime of the gitlab action. That might explain this weird behavior.
I don't use GitLab but check if there's a button somewhere to delete cache?

@Bathilde
Copy link
Author

Bathilde commented Apr 4, 2024

I don't have access to the machine directly, everything is controlled through a yml file containing the instructions. In my case I have the following instructions:

    - npm install
    - npm run build
    - npx sst telemetry disable
    - npx sst deploy --stage test

@conico974
Copy link
Collaborator

Try removing .next and .open-next, there must be some kind of cache on the gitlab server

@khuezy
Copy link
Collaborator

khuezy commented Apr 4, 2024

Does GitLab CI/CD action configuration let you configure the OS and node runtime? I'm assuming it does. Can you share the rest of the yml file?

Try adding a command to delete the .next and .open-next folder. But ideally, you'd want to cache those folders if nothing changed.

@bneilz
Copy link

bneilz commented Apr 4, 2024

I'm working with Bathilde. We run the deploy job with a custom docker image :

FROM registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest

RUN apt-get update
RUN apt install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt update
RUN apt install -y nodejs
RUN apt install gcc g++ make -y
RUN apt install -y python
RUN apt install -y postgresql
RUN apt install -y libpq-dev

And here is the Gitlab-CI job :

deploy-test:
  stage: deploy
  image: my-repo/sst-nodejs-build:latest
  rules:
  - if: '$CI_COMMIT_REF_NAME != "develop" || $CI_COMMIT_TAG'
    when: manual
  - if: $CI_COMMIT_REF_NAME
  environment:
    name: TEST
  script:
    - npm install
    - npm run build
    - npx sst deploy --stage test

@khuezy
Copy link
Collaborator

khuezy commented Apr 4, 2024

Can you try adding rm -rf .open-next .next (or where ever your next app and sst root is) before the npm run build step?

@bneilz
Copy link

bneilz commented Apr 5, 2024

We tried it. It changes nothing. And I added too a ls before run rm command and there are no .open-next and .next folders.

@bneilz
Copy link

bneilz commented Apr 5, 2024

Yesterday I tried to deploy from my computer and it worked. This morning I've deleted .next .open-next folders before deploying.
npm run build create .next folder, but there is no .open-next folder. Then I run npx sst deploy --stage test and I got this error :
ENOENT: no such file or directory, scandir 'C:\my-app-folder\front\.open-next\assets'

@conico974
Copy link
Collaborator

This might not be necessary to run npm run build (and if it runs in parallel, that might explain the issue) sst deploy also run the build command from your package.json by default.
Given the error that seems to change it's possible that it has something to do with tasks running in parallel.
FIY open-next is not supported on windows #385

@bneilz
Copy link

bneilz commented Apr 5, 2024

I added npm run build to try to fix our issue. Without it we have this error : ENOENT: no such file or directory, open 'C:\my-app-folder\.next\routes-manifest.json'

@bneilz
Copy link

bneilz commented Apr 5, 2024

And we have the same error on our gitlab job, which is not running on windows.

@conico974
Copy link
Collaborator

What's your build command in package.json? And what's inside your sst NextJsSite construct?

@bneilz
Copy link

bneilz commented Apr 5, 2024

Our build command is next build. Our sst.config.ts is :

import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
import { SSTConfig } from "sst";
import { NextjsSite, NextjsSiteProps } from "sst/constructs";

export default {
  config(_input) {
    return {
      name: "our-app",
      region: "eu-west-3",
    };
  },
  stacks(app) {
    app.stack(function Site({ stack }: { stack: any }) {
      let options: NextjsSiteProps | undefined = undefined;
      if (!!process.env['HOST'] && !!process.env['CERT_ARN']) {
        options = {
          customDomain: {
            domainName: process.env['HOST'] as string,
            isExternalDomain: true,
            cdk: {
              // @ts-ignore
              certificate: Certificate.fromCertificateArn(stack, "MyCert", process.env['CERT_ARN'] as string),
            },
          }
        };
      }
      const site = new NextjsSite(stack, "site", options);
      stack.addOutputs({
        SiteUrl: site.url,
      });
    });
  },
} satisfies SSTConfig;

@conico974
Copy link
Collaborator

Are you on a monorepo ? NX maybe ?
SST and OpenNext runs from the current working directory, it will execute the build command from the package in the cwd. It also expects the .next output to be in the cwd where the process has been called

@bneilz
Copy link

bneilz commented Apr 6, 2024

I found a solution. npx sst deploy does not run open-next build anymore. So I added npx open-next build before npx sst deploy to fix our deployment.
I don't know why open-next build is not run anymore by sst command but I'm pretty sure that it is not on "our" side because of this :
image
April 3, 2024 at 4:31:28 PM the job was OK and 2 hours later the same job (from same commit) was KO with no such file or directory, open '.next/routes-manifest.json'.

@conico974
Copy link
Collaborator

Pretty sure the issue is not on the OpenNext side either, there is no cache or anything that would stop the open-next build command.

There might be some kind of caching from either gitlab or sst that may stop the command (maybe because it's the same commit)

I'll close this issue as it doesn't seem related to OpenNext, you could open an issue in the SST repo.
Feel free to reopen the issue if it is indeed an error from OpenNext

@icarns
Copy link

icarns commented May 16, 2024

We have a similar error when we add to the Next.js resource

		buildCommand: 'pnpm run build',

We noticed that by default it uses npm, while in our monorepo we use pnpm, so we wanted to use pnpm there as well. It works locally, but not in GH Actions. After deleting the cache from GH, we still get the same error.

@khuezy
Copy link
Collaborator

khuezy commented May 16, 2024

We have a similar error when we add to the Next.js resource

		buildCommand: 'pnpm run build',

We noticed that by default it uses npm, while in our monorepo we use pnpm, so we wanted to use pnpm there as well. It works locally, but not in GH Actions. After deleting the cache from GH, we still get the same error.

https://github.com/sst/open-next/blob/main/packages/open-next/src/build.ts#L157-L200
It should detect your packager and use the appropriate command. Did you install pnpm in your GHA?

@icarns
Copy link

icarns commented Jul 11, 2024

We have a similar error when we add to the Next.js resource

		buildCommand: 'pnpm run build',

We noticed that by default it uses npm, while in our monorepo we use pnpm, so we wanted to use pnpm there as well. It works locally, but not in GH Actions. After deleting the cache from GH, we still get the same error.

https://github.com/sst/open-next/blob/main/packages/open-next/src/build.ts#L157-L200 It should detect your packager and use the appropriate command. Did you install pnpm in your GHA?

We use pnpm in our GH Actions by enabling it with corepack:

        run: corepack enable pnpm

Everything uses pnpm, so apparently there is no issue there.

After sst dev, we get the message

cd ... && npm run dev

Which is what makes us believe that it is still using npm. Is that true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants