opennextjs / opennextjs-netlify

Open Next.js adapter for Netlify
https://opennext.js.org/netlify
678 stars 87 forks source link

Error: No static assets found in .next dist (aka no /.next/static). Please check your project configuration. Your next.config.js must be one of `serverless` or `experimental-serverless-trace`. Your build command should include `next build`. #390

Closed davidli108 closed 3 years ago

davidli108 commented 3 years ago

Describe the bug I am using monorepo in my project. Monorepo foloder structure is

 - app
     - frontend
     - backend

I have netlify.toml file in app folder and next.config.js in frontend folder.

This is next.config.js file

module.exports = {
  target: "experimental-serverless-trace",
  distDir: '.next',
  images: {
    loader: 'imgix',
    path: ''
  }
}

And this is netlify.toml file

[build]
  command   = "npm run lint --prefix frontend && npm run build && npm run test && rm -rf /opt/buildhome/cache"
  publish   = "frontend/out"

[context.production.environment]
  NODE_OPTIONS="--max-old-space-size=4096"

[[plugins]]
  package = "@netlify/plugin-nextjs"

But I am getting an error as the title of this issue.

Plugin "@netlify/plugin-nextjs" internal error

Error: No static assets found in .next dist (aka no /.next/static). Please check your project configuration. Your next.config.js must be one of serverless or experimental-serverless-trace. Your build command should include next build.

In "onBuild" event in "@netlify/plugin-nextjs" from netlify.toml
at copyNextAssets (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/lib/steps/copyNextAssets.js:14:11)
at async build (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/index.js:25:3)
at async nextOnNetlify (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/src/index.js:75:5)
at async onBuild (/opt/build/repo/.netlify/plugins/node_modules/@netlify/plugin-nextjs/index.js:75:5)
at async Object.run (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/run.js:20:3)
at async handleEvent (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js:36:38)
at async process. (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/ipc.js:103:16) 

Expected behavior A clear and concise description of what you expected to happen.

Versions

If you're using the CLI to build

samiahmedsiddiqui commented 3 years ago

@davidli108 Trigger a build again. I was having this issue and when I simply redeploy from Netlify Dashboard then it works fine for me.

Give it aa try, it might help you as well.

davidli108 commented 3 years ago

@samiahmedsiddiqui Thanks for your comment. I tried a build several times but I am having same issues.

davidli108 commented 3 years ago

@samiahmedsiddiqui Could you please share your next.config.js and netlify.toml file? And please check my folder structure and config files. :)

Thank you.

lindsaylevine commented 3 years ago

@davidli108 hey david! thanks for opening this issue! do you have your base directory set in netlify? is there a specific reason you manually set distDir to '.next(that is what it defaults to). it's possible you might want to set distDir tofrontend/.next`. would be helpful to see your npm scripts too! on top of all those qs, a simple repo would be probably the most helpful :)

davidli108 commented 3 years ago

@lindsaylevine Thanks for your comment. I didn't set base directory.

My issue is happening in this line image

Here, staticAssetsPath is defined like this:

const nextDistDir = await getNextDistDir()  
const staticAssetsPath = join(nextDistDir, 'static')

And then, nextDistDir is defined like this: image

So I thought nextConfig.distDir has a problem. That's why I set distDir manually.

I look forward to hearing from you. Thank you

samiahmedsiddiqui commented 3 years ago

@davidli108 Please add console.log(staticAssetsPath) and see what it returns.

lindsaylevine commented 3 years ago

@davidli108 my suggestions right now:

  1. try to set your base directory to frontend in netlify
  2. if that doesn't work, try to set distDir to frontend/.next
  3. if that doesn't work, share a simple repo with us that reproduces your issue
lindsaylevine commented 3 years ago

hello! i now believe this is a duplicate of https://github.com/netlify/netlify-plugin-nextjs/issues/323 but would still need a repo to confirm. feel free to close this and follow #323 if you think it's the same issue or want to try the bandaid i offered simon.

pzi commented 3 years ago

I am getting the same error for my monorepo....

When looking into the .next and .next/static folders it's all there but the plugin doesn't seem to be able to pick it up...

See netlify build log ```bash 1:23:46 AM: Parsing package.json dependencies 1:23:46 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'web/.next' versus '' in the Netlify UI 1:23:46 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'yarn build-web; ls -alh web/.next/; ls -alh web/.next/static' versus '' in the Netlify UI 1:23:46 AM: Starting build script 1:23:46 AM: Installing dependencies 1:23:46 AM: Python version set to 2.7 1:23:47 AM: Started restoring cached node version 1:23:49 AM: Finished restoring cached node version 1:23:49 AM: Attempting node version 'v14.17.1' from .node-version 1:23:50 AM: Downloading and installing node v14.17.1... 1:23:50 AM: Downloading https://nodejs.org/dist/v14.17.1/node-v14.17.1-linux-x64.tar.xz... 1:23:50 AM: Computing checksum with sha256sum 1:23:50 AM: Checksums matched! 1:23:53 AM: Now using node v14.17.1 (npm v6.14.13) 1:23:53 AM: Started restoring cached build plugins 1:23:53 AM: Finished restoring cached build plugins 1:23:53 AM: Attempting ruby version 2.7.2, read from environment 1:23:55 AM: Using ruby version 2.7.2 1:23:55 AM: Using PHP version 5.6 1:23:55 AM: Started restoring cached yarn cache 1:23:55 AM: Finished restoring cached yarn cache 1:23:56 AM: No yarn workspaces detected 1:23:56 AM: Started restoring cached node modules 1:23:56 AM: Finished restoring cached node modules 1:23:56 AM: Installing NPM modules using Yarn version 1.22.10 1:23:56 AM: yarn install v1.22.10 1:23:56 AM: [1/4] Resolving packages... 1:23:57 AM: warning wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @vercel/nft > acorn-import-meta@1.1.0: acorn>=7.2 supports import-meta 1:23:57 AM: warning wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @vercel/nft > acorn-export-ns-from@0.1.0: acorn>=7.2 supports export-ns-from 1:23:57 AM: warning wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @vercel/nft > acorn-numeric-separator@0.3.6: acorn>=7.4 supports numeric separators 1:23:57 AM: warning wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @vercel/nft > node-pre-gyp@0.13.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future 1:23:58 AM: warning wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @aws-sdk/client-s3 > @aws-sdk/middleware-retry > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. 1:23:59 AM: [2/4] Fetching packages... 1:24:49 AM: info fsevents@2.3.2: The platform "linux" is incompatible with this module. 1:24:49 AM: info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. 1:24:49 AM: info fsevents@1.2.13: The platform "linux" is incompatible with this module. 1:24:49 AM: info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. 1:24:49 AM: info @netlify/routing-local-proxy-darwin-arm64@0.30.1: The platform "linux" is incompatible with this module. 1:24:49 AM: info "@netlify/routing-local-proxy-darwin-arm64@0.30.1" is an optional dependency and failed compatibility check. Excluding it from installation. 1:24:49 AM: info @netlify/routing-local-proxy-darwin-arm64@0.30.1: The CPU architecture "x64" is incompatible with this module. 1:24:49 AM: info @netlify/routing-local-proxy-darwin-x64@0.30.1: The platform "linux" is incompatible with this module. 1:24:49 AM: info "@netlify/routing-local-proxy-darwin-x64@0.30.1" is an optional dependency and failed compatibility check. Excluding it from installation. 1:24:49 AM: info @netlify/routing-local-proxy-win32-x64@0.30.1: The platform "linux" is incompatible with this module. 1:24:49 AM: info "@netlify/routing-local-proxy-win32-x64@0.30.1" is an optional dependency and failed compatibility check. Excluding it from installation. 1:24:49 AM: [3/4] Linking dependencies... 1:24:49 AM: warning "wabainc-studio > @sanity/base > react-sortable-hoc@1.11.0" has incorrect peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/base > react-sortable-hoc@1.11.0" has incorrect peer dependency "react-dom@^0.14.0 || ^15.0.0 || ^16.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/base > react-split-pane@0.1.92" has incorrect peer dependency "react@^16.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/base > react-split-pane@0.1.92" has incorrect peer dependency "react-dom@^16.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/base > styled-components@5.3.0" has unmet peer dependency "react-is@>= 16.8.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/plugin-proposal-class-properties@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-typescript@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/register@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @sanity/webpack-integration@2.11.0" has unmet peer dependency "webpack@>= 1.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/desk-tool > react-json-inspector@7.1.1" has incorrect peer dependency "react@^15.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/desk-tool > react-tiny-virtual-list@2.2.0" has incorrect peer dependency "react@15.x || 16.x". 1:24:49 AM: warning "wabainc-studio > @sanity/vision > react-codemirror2@6.0.1" has incorrect peer dependency "react@>=15.5 <=16.x". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/plugin-proposal-class-properties > @babel/helper-create-class-features-plugin@7.14.6" has unmet peer dependency "@babel/core@^7.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/helper-compilation-targets@7.14.5" has unmet peer dependency "@babel/core@^7.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5" has unmet peer dependency "@babel/core@^7.13.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-async-generator-functions@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-class-static-block@7.14.5" has unmet peer dependency "@babel/core@^7.12.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-dynamic-import@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-export-namespace-from@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-json-strings@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-logical-assignment-operators@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-nullish-coalescing-operator@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-numeric-separator@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-object-rest-spread@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-optional-catch-binding@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-optional-chaining@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-private-methods@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-private-property-in-object@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-unicode-property-regex@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-async-generators@7.8.4" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-class-properties@7.12.13" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-class-static-block@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-dynamic-import@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-export-namespace-from@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-json-strings@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-logical-assignment-operators@7.10.4" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-nullish-coalescing-operator@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-numeric-separator@7.10.4" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-object-rest-spread@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-optional-catch-binding@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-optional-chaining@7.8.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-private-property-in-object@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-syntax-top-level-await@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-arrow-functions@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-async-to-generator@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-block-scoped-functions@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-block-scoping@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-classes@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-computed-properties@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-destructuring@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-dotall-regex@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-duplicate-keys@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-exponentiation-operator@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-for-of@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-function-name@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-literals@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-member-expression-literals@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-modules-amd@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-modules-commonjs@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-modules-systemjs@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-modules-umd@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-named-capturing-groups-regex@7.14.5" has unmet peer dependency "@babel/core@^7.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-new-target@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-object-super@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-parameters@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-property-literals@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-regenerator@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-reserved-words@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-shorthand-properties@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-spread@7.14.6" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-sticky-regex@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-template-literals@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-typeof-symbol@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-unicode-escapes@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-transform-unicode-regex@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/preset-modules@0.1.4" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > babel-plugin-polyfill-corejs2@0.2.2" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > babel-plugin-polyfill-corejs3@0.2.3" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > babel-plugin-polyfill-regenerator@0.2.2" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react > @babel/plugin-transform-react-display-name@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react > @babel/plugin-transform-react-jsx@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react > @babel/plugin-transform-react-jsx-development@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react > @babel/plugin-transform-react-pure-annotations@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-typescript > @babel/plugin-transform-typescript@7.14.6" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @sanity/server > @hot-loader/react-dom@16.14.0" has incorrect peer dependency "react@^16.14.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @sanity/webpack-integration > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > @babel/plugin-proposal-unicode-property-regex > @babel/helper-create-regexp-features-plugin@7.14.5" has unmet peer dependency "@babel/core@^7.0.0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-env > babel-plugin-polyfill-corejs2 > @babel/helper-define-polyfill-provider@0.2.3" has unmet peer dependency "@babel/core@^7.4.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-react > @babel/plugin-transform-react-jsx > @babel/plugin-syntax-jsx@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-studio > @sanity/core > @babel/preset-typescript > @babel/plugin-transform-typescript > @babel/plugin-syntax-typescript@7.14.5" has unmet peer dependency "@babel/core@^7.0.0-0". 1:24:49 AM: warning "wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @vercel/nft > acorn-export-ns-from@0.1.0" has incorrect peer dependency "acorn@^6.0.1". 1:24:49 AM: warning "wabainc-web > @netlify/plugin-nextjs > @sls-next/lambda-at-edge > @aws-sdk/client-s3 > @aws-sdk/middleware-retry > react-native-get-random-values@1.7.0" has unmet peer dependency "react-native@>=0.56". 1:24:49 AM: warning " > eslint-config-next@11.0.0" has unmet peer dependency "next@>=10.2.0". 1:24:49 AM: warning Workspaces can only be enabled in private projects. 1:24:49 AM: warning Workspaces can only be enabled in private projects. 1:24:49 AM: warning Workspaces can only be enabled in private projects. 1:24:49 AM: warning Workspaces can only be enabled in private projects. 1:25:17 AM: [4/4] Building fresh packages... 1:25:23 AM: success Saved lockfile. 1:25:23 AM: $ lerna bootstrap 1:25:24 AM: lerna notice cli v4.0.0 1:25:24 AM: lerna info ci enabled 1:25:24 AM: lerna info bootstrap root only 1:25:24 AM: yarn install v1.22.10 1:25:24 AM: [1/4] Resolving packages... 1:25:25 AM: success Already up-to-date. 1:25:25 AM: $ lerna bootstrap 1:25:25 AM: lerna notice cli v4.0.0 1:25:25 AM: lerna info ci enabled 1:25:26 AM: lerna WARN bootstrap Skipping recursive execution 1:25:26 AM: $ husky install 1:25:26 AM: husky - Git hooks installed 1:25:26 AM: Done in 1.73s. 1:25:26 AM: $ husky install 1:25:26 AM: husky - Git hooks installed 1:25:26 AM: Done in 89.55s. 1:25:26 AM: NPM modules installed using Yarn 1:25:26 AM: Started restoring cached go cache 1:25:26 AM: Finished restoring cached go cache 1:25:26 AM: go version go1.14.4 linux/amd64 1:25:26 AM: go version go1.14.4 linux/amd64 1:25:26 AM: Installing missing commands 1:25:26 AM: Verify run directory 1:25:27 AM: ​ 1:25:27 AM: ──────────────────────────────────────────────────────────────── 1:25:27 AM: Netlify Build 1:25:27 AM: ──────────────────────────────────────────────────────────────── 1:25:27 AM: ​ 1:25:27 AM: ❯ Version 1:25:27 AM: @netlify/build 12.4.0 1:25:27 AM: ​ 1:25:27 AM: ❯ Flags 1:25:27 AM: deployId: 60d0cb18d6b4ac0008fa5652 1:25:27 AM: ​ 1:25:27 AM: ❯ Current directory 1:25:27 AM: /opt/build/repo 1:25:27 AM: ​ 1:25:27 AM: ❯ Config file 1:25:27 AM: /opt/build/repo/netlify.toml 1:25:27 AM: ​ 1:25:27 AM: ❯ Context 1:25:27 AM: production 1:25:27 AM: ​ 1:25:27 AM: ❯ Loading plugins 1:25:27 AM: - @netlify/plugin-nextjs@3.4.2 from netlify.toml and package.json 1:25:27 AM: ​ 1:25:27 AM: ──────────────────────────────────────────────────────────────── 1:25:27 AM: 1. onPreBuild command from @netlify/plugin-nextjs 1:25:27 AM: ──────────────────────────────────────────────────────────────── 1:25:27 AM: ​ 1:25:27 AM: ** Warning: support for Next.js >=11.0.0 is experimental ** 1:25:28 AM: info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5 1:25:28 AM: Next.js cache restored. 1:25:28 AM: ​ 1:25:28 AM: (@netlify/plugin-nextjs onPreBuild completed in 880ms) 1:25:28 AM: ​ 1:25:28 AM: ──────────────────────────────────────────────────────────────── 1:25:28 AM: 2. build.command from netlify.toml 1:25:28 AM: ──────────────────────────────────────────────────────────────── 1:25:28 AM: ​ 1:25:28 AM: $ yarn build-web; ls -alh web/.next/; ls -alh web/.next/static 1:25:28 AM: yarn run v1.22.10 1:25:28 AM: $ lerna bootstrap && (cd web && yarn build) 1:25:29 AM: lerna notice cli v4.0.0 1:25:29 AM: lerna info ci enabled 1:25:29 AM: lerna info bootstrap root only 1:25:29 AM: [1/4] Resolving packages... 1:25:30 AM: success Already up-to-date. 1:25:30 AM: $ lerna bootstrap 1:25:31 AM: lerna notice cli v4.0.0 1:25:31 AM: lerna info ci enabled 1:25:31 AM: lerna WARN bootstrap Skipping recursive execution 1:25:31 AM: $ husky install 1:25:31 AM: husky - Git hooks installed 1:25:31 AM: $ next build 1:25:32 AM: info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5 1:25:32 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache 1:25:32 AM: info - Checking validity of types... 1:25:39 AM: info - Creating an optimized production build... 1:25:44 AM: warn - You have enabled the JIT engine which is currently in preview. 1:25:44 AM: warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time. 1:26:02 AM: (node:1908) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API 1:26:02 AM: (Use `node --trace-deprecation ...` to show where the warning was created) 1:26:03 AM: warn - Compiled with warnings 1:26:03 AM: ../node_modules/next/dist/next-server/server/load-components.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: ../node_modules/next/dist/next-server/server/load-components.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: ../node_modules/next/dist/next-server/server/load-components.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: ../node_modules/next/dist/next-server/server/require.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: ../node_modules/next/dist/next-server/server/require.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: ../node_modules/next/dist/next-server/server/require.js 1:26:03 AM: Critical dependency: the request of a dependency is an expression 1:26:03 AM: info - Collecting page data... 1:26:04 AM: info - Generating static pages (0/8) 1:26:05 AM: info - Generating static pages (2/8) 1:26:06 AM: info - Generating static pages (4/8) 1:26:06 AM: info - Generating static pages (6/8) 1:26:06 AM: info - Generating static pages (8/8) 1:26:06 AM: info - Finalizing page optimization... 1:26:06 AM: Page Size First Load JS 1:26:06 AM: ┌ ○ / 1.18 kB 69.5 kB 1:26:06 AM: ├ /_app 0 B 64.9 kB 1:26:06 AM: ├ ○ /404 3.18 kB 68.1 kB 1:26:06 AM: ├ λ /api/exit-preview 0 B 64.9 kB 1:26:06 AM: ├ λ /api/preview 0 B 64.9 kB 1:26:06 AM: └ ● /posts/[slug] 40.5 kB 109 kB 1:26:06 AM: ├ /posts/first-live-post 1:26:06 AM: ├ /posts/the-third-of-all 1:26:06 AM: ├ /posts/my-only-post 1:26:06 AM: └ [+2 more paths] 1:26:06 AM: + First Load JS shared by all 64.9 kB 1:26:06 AM: ├ chunks/framework.f076ac.js 42.4 kB 1:26:06 AM: ├ chunks/main.0961e7.js 20.3 kB 1:26:06 AM: ├ chunks/pages/_app.21c550.js 556 B 1:26:06 AM: ├ chunks/webpack.cbce84.js 1.67 kB 1:26:06 AM: └ css/46e6c94abbf9326e3feb.css 2.84 kB 1:26:06 AM: λ (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps) 1:26:06 AM: ○ (Static) automatically rendered as static HTML (uses no initial props) 1:26:06 AM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps) 1:26:06 AM: (ISR) incremental static regeneration (uses revalidate in getStaticProps) 1:26:06 AM: Done in 37.46s. 1:26:06 AM: total 52K 1:26:06 AM: drwxr-xr-x 5 buildbot nogroup 4.0K Jun 21 17:26 . 1:26:06 AM: drwxr-xr-x 9 buildbot root 4.0K Jun 21 17:25 .. 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 21 Jun 21 17:26 BUILD_ID 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 1.5K Jun 21 17:25 build-manifest.json 1:26:06 AM: drwxr-xr-x 3 buildbot nogroup 4.0K Jun 21 17:25 cache 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 94 Jun 21 17:26 export-marker.json 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 275 Jun 21 17:26 images-manifest.json 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 1.4K Jun 21 17:26 prerender-manifest.json 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 178 Jun 21 17:25 react-loadable-manifest.json 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 1.6K Jun 21 17:26 required-server-files.json 1:26:06 AM: -rw-r--r-- 1 buildbot nogroup 595 Jun 21 17:26 routes-manifest.json 1:26:06 AM: drwxr-xr-x 4 buildbot nogroup 4.0K Jun 21 17:26 serverless 1:26:06 AM: drwxr-xr-x 5 buildbot nogroup 4.0K Jun 21 17:25 static 1:26:06 AM: total 20K 1:26:06 AM: drwxr-xr-x 5 buildbot nogroup 4.0K Jun 21 17:25 . 1:26:06 AM: drwxr-xr-x 5 buildbot nogroup 4.0K Jun 21 17:26 .. 1:26:06 AM: drwxr-xr-x 2 buildbot nogroup 4.0K Jun 21 17:25 4WnbzgNsJ3WqtCFTJRmau 1:26:06 AM: drwxr-xr-x 3 buildbot nogroup 4.0K Jun 21 17:25 chunks 1:26:06 AM: drwxr-xr-x 2 buildbot nogroup 4.0K Jun 21 17:25 css 1:26:06 AM: ​ 1:26:06 AM: (build.command completed in 37.8s) 1:26:06 AM: ​ 1:26:06 AM: ──────────────────────────────────────────────────────────────── 1:26:06 AM: 3. onBuild command from @netlify/plugin-nextjs 1:26:06 AM: ──────────────────────────────────────────────────────────────── 1:26:06 AM: ​ 1:26:06 AM: ** Running Next on Netlify package ** 1:26:06 AM: 🚀 Next on Netlify 🚀 1:26:06 AM: ​ 1:26:06 AM: ──────────────────────────────────────────────────────────────── 1:26:06 AM: Plugin "@netlify/plugin-nextjs" internal error 1:26:06 AM: ──────────────────────────────────────────────────────────────── 1:26:06 AM: ​ 1:26:06 AM: Error message 1:26:06 AM: Error: No static assets found in .next dist (aka no /.next/static). Please check your project configuration. Your next.config.js must be one of `serverless` or `experimental-serverless-trace`. Your build command should include `next build`. 1:26:06 AM: ​ 1:26:06 AM: Plugin details 1:26:06 AM: Package: @netlify/plugin-nextjs 1:26:06 AM: Version: 3.4.2 1:26:06 AM: Repository: git+https://github.com/netlify/netlify-plugin-nextjs.git 1:26:06 AM: npm link: https://www.npmjs.com/package/@netlify/plugin-nextjs 1:26:06 AM: Report issues: https://github.com/netlify/netlify-plugin-nextjs/issues 1:26:06 AM: ​ 1:26:06 AM: Error location 1:26:06 AM: In "onBuild" event in "@netlify/plugin-nextjs" from netlify.toml and package.json 1:26:06 AM: at copyNextAssets (/opt/build/repo/node_modules/@netlify/plugin-nextjs/src/lib/steps/copyNextAssets.js:14:11) 1:26:06 AM: at async build (/opt/build/repo/node_modules/@netlify/plugin-nextjs/src/index.js:25:3) 1:26:06 AM: at async nextOnNetlify (/opt/build/repo/node_modules/@netlify/plugin-nextjs/src/index.js:75:5) 1:26:06 AM: at async onBuild (/opt/build/repo/node_modules/@netlify/plugin-nextjs/index.js:75:5) 1:26:06 AM: at async Object.run (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/run.js:20:3) 1:26:06 AM: at async handleEvent (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js:36:38) 1:26:06 AM: at async process. (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/ipc.js:103:16) 1:26:06 AM: ​ 1:26:06 AM: Resolved config 1:26:06 AM: build: 1:26:06 AM: base: /opt/build/repo 1:26:06 AM: command: yarn build-web; ls -alh web/.next/; ls -alh web/.next/static 1:26:06 AM: commandOrigin: config 1:26:06 AM: environment: 1:26:06 AM: - NEXT_PUBLIC_SANITY_DATASET 1:26:06 AM: - NEXT_PUBLIC_SANITY_PROJECT_ID 1:26:06 AM: - SANITY_API_TOKEN 1:26:06 AM: - SANITY_PREVIEW_SECRET 1:26:06 AM: publish: /opt/build/repo/web/.next 1:26:06 AM: functions: 1:26:06 AM: '*': {} 1:26:06 AM: plugins: 1:26:06 AM: - inputs: {} 1:26:06 AM: origin: config 1:26:06 AM: package: '@netlify/plugin-nextjs' ```

netlify.toml

[build]
  base = "/"
  publish = "/web/.next/"  #  or /web/ for that matter
  command = "yarn build-web; ls -alh web/.next/; ls -alh web/.next/static"

[[plugins]]
  package = "@netlify/plugin-nextjs"

next.config.js

const nextConfig = {
  reactStrictMode: true,
  target: 'serverless',
  future: undefined,
  experimental: undefined,
};

module.exports = nextConfig;

Scripts:

# root
"build-web": "lerna bootstrap && (cd web && yarn build)",

# web
"build": "next build",

monorepo structure:


- repo/
  - lerna.json
  - package.json
  - web/
    - package.json
  - studio/
    - package.json
pzi commented 3 years ago

Looks like I can get it to pick up the files if I set my next.config.js distDir to ../.next which seems to get me a little further but it then breaks because it's missing a dependency:

Build log ```bash 2:01:04 AM: Packaging Functions from netlify/functions directory: 2:01:04 AM: - next_image.js 2:01:04 AM: - next_api_exitpreview/next_api_exitpreview.js 2:01:04 AM: - next_api_preview/next_api_preview.js 2:01:04 AM: - next_posts_slug/next_posts_slug.js 2:01:04 AM: ​ 2:01:07 AM: ​ 2:01:07 AM: ──────────────────────────────────────────────────────────────── 2:01:07 AM: Dependencies installation error 2:01:07 AM: ──────────────────────────────────────────────────────────────── 2:01:07 AM: ​ 2:01:07 AM: Error message 2:01:07 AM: A Netlify Function failed to require one of its dependencies. 2:01:07 AM: Please make sure it is present in the site's top-level "package.json". ​ 2:01:07 AM: In file "/opt/build/repo/netlify/functions/next_posts_slug/next_posts_slug.js" 2:01:07 AM: Cannot find module 'critters' 2:01:07 AM: Require stack: 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/src/main.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins_core/functions/index.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/commands/get.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/main.js 2:01:07 AM: - /opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/core/bin.js ```
lindsaylevine commented 3 years ago

@pzi hey! thanks for letting us know what's going on in your monorepo setup. helpful for us moving forward! if you wanted to provide us with a repo we can test against once we address all these issues, that would be even more helpful! #323 could possibly guide you on how to set your publish dir and next dist. also, per https://nextjs.org/docs/api-reference/next.config.js/setting-a-custom-build-directory, your distDir should not go up to parent dirs. not sure why you're seeing cannot find module critters, it's an outdated issue 🤔 . possibly try adding esbuild to your netlify.toml per https://docs.netlify.com/configure-builds/file-based-configuration/#functions. anyways, hang tight~!!

lindsaylevine commented 3 years ago

note: esbuild breaks dynamic imports, if you're using those in your site. we're working on a fix for this!

pzi commented 3 years ago

Oh, I totally agree I shouldn’t have to set the distDir to go one dir up :) I just did that to check if the plugin considers the publish dir.

Unfortunately, for now at least, the repo is private and I can’t share it.

I will give the changes and maybe esbuild a try later, thanks for looking into it!

pzi commented 3 years ago

It feels like that something like the below might address the issue we are experiencing?

const getNextDistDir = async (publishPath) => {
  const nextConfig = await getNextConfig()

  return join(publishPath, nextConfig.distDir)
}
lindsaylevine commented 3 years ago

@pzi yep thats basically what we go over here: https://github.com/netlify/netlify-plugin-nextjs/issues/323#issuecomment-859208810 :)

ascorbic commented 3 years ago

I've written up a summary of this and related issues, along with some potential solutions in a new issue: #433

lindsaylevine commented 3 years ago

hey all! thanks for your patience on this. per matt's issue #433, we'll close this in favor of that. please follow along and leave feedback there, but we'll try to circle back here, too, whenever we release support! 🙏

ascorbic commented 3 years ago

Could anyone who experienced this try installing @netlify/plugin-nextjs@latest and see if it works? Version 3.6.0 adds much better monorepo support. Docs are here