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

npm run build doesn't work at a filesystem root #62591

Open
x-yuri opened this issue Feb 27, 2024 · 0 comments
Open

npm run build doesn't work at a filesystem root #62591

x-yuri opened this issue Feb 27, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`.

Comments

@x-yuri
Copy link

x-yuri commented Feb 27, 2024

Link to the code that reproduces this issue

https://github.com/x-yuri/issues/tree/next-build-root

To Reproduce

Dockerfile:

FROM node:20.11.1-alpine3.19 as packages
COPY package*.json .
RUN npm install

FROM node:20.11.1-alpine3.19 as build
ENV NODE_ENV=production

# good
# WORKDIR /app

COPY --from=packages /node_modules node_modules
COPY . .
RUN npx next build

FROM node:20.11.1-alpine3.19
WORKDIR /app

# good
# COPY --from=build /app/.next/standalone .
# COPY --from=build /app/.next/static .next/static

# bad
COPY --from=build /.next/standalone .
COPY --from=build /.next/static .next/static
$ echo '{"name": "app"}' > package.json
$ npm i react react-dom next
$ mkdir pages
$ echo 'export default () => "hello world";' > pages/index.js
$ echo 'export default {output: "standalone"}' > next.config.mjs
$ echo $'.next\nnode_modules' > .dockerignore
$ docker build -t i . && docker run --rm i node server.js
...
node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'next/dist/compiled/find-up'
Require stack:
- /app/node_modules/next/dist/server/config.js
- /app/node_modules/next/dist/server/next.js
- /app/server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at /app/node_modules/next/dist/server/require-hook.js:55:36
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at mod.require (/app/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/app/node_modules/next/dist/server/config.js:38:56)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/next/dist/server/config.js',
    '/app/node_modules/next/dist/server/next.js',
    '/app/server.js'
  ]
}

Node.js v20.11.1
node_modules diff
$ docker build -t i .
$ docker run --rm i sh -euc \
    'mv node_modules node_modules-bad; tar c node_modules-bad' \
    | tar x
// Dockerfile: comment out the bad parts, uncomment the good ones
$ docker build -t i .
$ docker run --rm i sh -euc \
    'mv node_modules node_modules-good; tar c node_modules-good' \
    | tar x
$ diff -urq node_modules-bad node_modules-good | less
Only in node_modules-good: busboy
Only in node_modules-good: caniuse-lite
Only in node_modules-good: client-only
Only in node_modules-good: graceful-fs
Only in node_modules-good: nanoid
Only in node_modules-good: @next
Only in node_modules-good/next/dist/build/polyfills: fetch
Only in node_modules-good/next/dist/build/polyfills: object.assign
Only in node_modules-good/next/dist/build/polyfills: object-assign.js
Only in node_modules-good/next/dist/client/components: bailout-to-client-rendering.js
Only in node_modules-good/next/dist/client/components: client-hook-in-server-component-error.js
Only in node_modules-good/next/dist/client/components: dev-root-not-found-boundary.js
Only in node_modules-good/next/dist/client/components: match-segments.js
Only in node_modules-good/next/dist/client/components: navigation.js
Only in node_modules-good/next/dist/client/components: not-found-boundary.js
Only in node_modules-good/next/dist/client/components: not-found-error.js
Only in node_modules-good/next/dist/client/components: parallel-route-default.js
Only in node_modules-good/next/dist/client/components: router-reducer
Only in node_modules-good/next/dist/client/components: static-generation-async-storage.external.js
Only in node_modules-good/next/dist/client/components: static-generation-bailout.js
Only in node_modules-good/next/dist/compiled: acorn
Only in node_modules-good/next/dist/compiled: amphtml-validator
Only in node_modules-good/next/dist/compiled: assert
Only in node_modules-good/next/dist/compiled: async-retry
Only in node_modules-good/next/dist/compiled: async-sema
Only in node_modules-good/next/dist/compiled: babel
Only in node_modules-good/next/dist/compiled: babel-packages
Only in node_modules-good/next/dist/compiled: browserify-zlib
Only in node_modules-good/next/dist/compiled: browserslist
Only in node_modules-good/next/dist/compiled: buffer
Only in node_modules-good/next/dist/compiled: bytes
Only in node_modules-good/next/dist/compiled: ci-info
Only in node_modules-good/next/dist/compiled: cli-select
Only in node_modules-good/next/dist/compiled: comment-json
Only in node_modules-good/next/dist/compiled: compression
Only in node_modules-good/next/dist/compiled: conf
Only in node_modules-good/next/dist/compiled: constants-browserify
Only in node_modules-good/next/dist/compiled: content-disposition
Only in node_modules-good/next/dist/compiled: cookie
Only in node_modules-good/next/dist/compiled: cross-spawn
Only in node_modules-good/next/dist/compiled: crypto-browserify
Only in node_modules-good/next/dist/compiled: cssnano-simple
Only in node_modules-good/next/dist/compiled: debug
Only in node_modules-good/next/dist/compiled: devalue
Only in node_modules-good/next/dist/compiled: domain-browser
Only in node_modules-good/next/dist/compiled: @edge-runtime
Only in node_modules-good/next/dist/compiled: edge-runtime
Only in node_modules-good/next/dist/compiled: events
Only in node_modules-good/next/dist/compiled: find-up
Only in node_modules-good/next/dist/compiled: fresh
Only in node_modules-good/next/dist/compiled: get-orientation
Only in node_modules-good/next/dist/compiled: glob
Only in node_modules-good/next/dist/compiled: gzip-size
Only in node_modules-good/next/dist/compiled: @hapi
Only in node_modules-good/next/dist/compiled: http-proxy
Only in node_modules-good/next/dist/compiled: http-proxy-agent
Only in node_modules-good/next/dist/compiled: https-browserify
Only in node_modules-good/next/dist/compiled: https-proxy-agent
Only in node_modules-good/next/dist/compiled: icss-utils
Only in node_modules-good/next/dist/compiled: ignore-loader
Only in node_modules-good/next/dist/compiled: image-size
Only in node_modules-good/next/dist/compiled: is-animated
Only in node_modules-good/next/dist/compiled: is-docker
Only in node_modules-good/next/dist/compiled: is-wsl
Only in node_modules-good/next/dist/compiled/jest-worker: index.js
Only in node_modules-good/next/dist/compiled/jest-worker: package.json
Only in node_modules-good/next/dist/compiled: json5
Only in node_modules-good/next/dist/compiled: jsonwebtoken
Only in node_modules-good/next/dist/compiled: loader-utils2
Only in node_modules-good/next/dist/compiled: loader-utils3
Only in node_modules-good/next/dist/compiled: lodash.curry
Only in node_modules-good/next/dist/compiled: lru-cache
Only in node_modules-good/next/dist/compiled: micromatch
Only in node_modules-good/next/dist/compiled: mini-css-extract-plugin
Only in node_modules-good/next/dist/compiled: @mswjs
Only in node_modules-good/next/dist/compiled: nanoid
Only in node_modules-good/next/dist/compiled: @napi-rs
Only in node_modules-good/next/dist/compiled: native-url
Only in node_modules-good/next/dist/compiled: neo-async
Only in node_modules-good/next/dist/compiled: @next
Only in node_modules-good/next/dist/compiled: next-server
Only in node_modules-good/next/dist/compiled: node-fetch
Only in node_modules-good/next/dist/compiled: node-html-parser
Only in node_modules-good/next/dist/compiled: @opentelemetry
Only in node_modules-good/next/dist/compiled: ora
Only in node_modules-good/next/dist/compiled: os-browserify
Only in node_modules-good/next/dist/compiled: path-browserify
Only in node_modules-good/next/dist/compiled: path-to-regexp
Only in node_modules-good/next/dist/compiled: p-limit
Only in node_modules-good/next/dist/compiled: postcss-flexbugs-fixes
Only in node_modules-good/next/dist/compiled: postcss-modules-extract-imports
Only in node_modules-good/next/dist/compiled: postcss-modules-local-by-default
Only in node_modules-good/next/dist/compiled: postcss-modules-scope
Only in node_modules-good/next/dist/compiled: postcss-modules-values
Only in node_modules-good/next/dist/compiled: postcss-plugin-stub-for-cssnano-simple
Only in node_modules-good/next/dist/compiled: postcss-preset-env
Only in node_modules-good/next/dist/compiled: postcss-scss
Only in node_modules-good/next/dist/compiled: postcss-value-parser
Only in node_modules-good/next/dist/compiled: process
Only in node_modules-good/next/dist/compiled: punycode
Only in node_modules-good/next/dist/compiled: querystring-es3
Only in node_modules-good/next/dist/compiled: react-is
Only in node_modules-good/next/dist/compiled: react-refresh
Only in node_modules-good/next/dist/compiled: regenerator-runtime
Only in node_modules-good/next/dist/compiled: sass-loader
Only in node_modules-good/next/dist/compiled: schema-utils3
Only in node_modules-good/next/dist/compiled: semver
Only in node_modules-good/next/dist/compiled: send
Only in node_modules-good/next/dist/compiled: setimmediate
Only in node_modules-good/next/dist/compiled: source-map
Only in node_modules-good/next/dist/compiled: stream-browserify
Only in node_modules-good/next/dist/compiled: stream-http
Only in node_modules-good/next/dist/compiled: string_decoder
Only in node_modules-good/next/dist/compiled: string-hash
Only in node_modules-good/next/dist/compiled: strip-ansi
Only in node_modules-good/next/dist/compiled: superstruct
Only in node_modules-good/next/dist/compiled: tar
Only in node_modules-good/next/dist/compiled: text-table
Only in node_modules-good/next/dist/compiled: timers-browserify
Only in node_modules-good/next/dist/compiled: tty-browserify
Only in node_modules-good/next/dist/compiled: unistore
Only in node_modules-good/next/dist/compiled: util
Only in node_modules-good/next/dist/compiled: @vercel
Only in node_modules-good/next/dist/compiled: vm-browserify
Only in node_modules-good/next/dist/compiled: watchpack
Only in node_modules-good/next/dist/compiled: webpack
Only in node_modules-good/next/dist/compiled: ws
Only in node_modules-good/next/dist/compiled: zod
Only in node_modules-good/next/dist: experimental
Only in node_modules-good/next/dist/lib/metadata: clone-metadata.js
Only in node_modules-good/next/dist/lib/metadata: constants.js
Only in node_modules-good/next/dist/lib/metadata: default-metadata.js
Only in node_modules-good/next/dist/lib/metadata: generate
Only in node_modules-good/next/dist/lib/metadata: metadata.js
Only in node_modules-good/next/dist/lib/metadata: resolve-metadata.js
Only in node_modules-good/next/dist/lib/metadata: resolvers
Only in node_modules-good/next/dist/lib: semver-noop.js
Only in node_modules-good/next/dist/server/app-render: action-handler.js
Only in node_modules-good/next/dist/server/app-render: app-render.js
Only in node_modules-good/next/dist/server/app-render: create-component-styles-and-scripts.js
Only in node_modules-good/next/dist/server/app-render: create-component-tree.js
Only in node_modules-good/next/dist/server/app-render: create-error-handler.js
Only in node_modules-good/next/dist/server/app-render: create-flight-router-state-from-loader-tree.js
Only in node_modules-good/next/dist/server/app-render: create-server-components-renderer.js
Only in node_modules-good/next/dist/server/app-render: csrf-protection.js
Only in node_modules-good/next/dist/server/app-render: flight-render-result.js
Only in node_modules-good/next/dist/server/app-render: get-asset-query-string.js
Only in node_modules-good/next/dist/server/app-render: get-css-inlined-link-tags.js
Only in node_modules-good/next/dist/server/app-render: get-layer-assets.js
Only in node_modules-good/next/dist/server/app-render: get-preloadable-fonts.js
Only in node_modules-good/next/dist/server/app-render: get-script-nonce-from-header.js
Only in node_modules-good/next/dist/server/app-render: get-segment-param.js
Only in node_modules-good/next/dist/server/app-render: get-short-dynamic-param-type.js
Only in node_modules-good/next/dist/server/app-render: has-loading-component-in-tree.js
Only in node_modules-good/next/dist/server/app-render: interop-default.js
Only in node_modules-good/next/dist/server/app-render: make-get-server-inserted-html.js
Only in node_modules-good/next/dist/server/app-render: parse-and-validate-flight-router-state.js
Only in node_modules-good/next/dist/server/app-render: parse-loader-tree.js
Only in node_modules-good/next/dist/server/app-render: react-server.node.js
Only in node_modules-good/next/dist/server/app-render: required-scripts.js
Only in node_modules-good/next/dist/server/app-render: server-inserted-html.js
Only in node_modules-good/next/dist/server/app-render: static
Only in node_modules-good/next/dist/server/app-render: types.js
Only in node_modules-good/next/dist/server/app-render: use-flight-response.js
Only in node_modules-good/next/dist/server/app-render: validate-url.js
Only in node_modules-good/next/dist/server/app-render: walk-tree-with-flight-router-state.js
Only in node_modules-good/next/dist/server/async-storage: draft-mode-provider.js
Only in node_modules-good/next/dist/server/async-storage: request-async-storage-wrapper.js
Only in node_modules-good/next/dist/server: capsize-font-metrics.json
Only in node_modules-good/next/dist/server/future/route-modules/app-page: module.js
Only in node_modules-good/next/dist/server/future/route-modules/app-page/vendored: rsc
Only in node_modules-good/next/dist/server/future/route-modules/app-page/vendored: ssr
Only in node_modules-good/next/dist/server: htmlescape.js
Only in node_modules-good/next/dist/server/lib: app-dir-module.js
Only in node_modules-good/next: font
Only in node_modules-good: picocolors
Only in node_modules-good: postcss
Only in node_modules-good: react
Only in node_modules-good: react-dom
Only in node_modules-good: scheduler
Only in node_modules-good: source-map-js
Only in node_modules-good: streamsearch
Only in node_modules-good: @swc

Current vs. Expected behavior

I expect it to produce a working build even if run at /.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Mon, 05 Feb 2024 22:07:49 +0000
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: standalone


warn  - Latest canary version not detected, detected: "14.1.0", newest: "14.1.1-canary.74".
        Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
        Read more - https://nextjs.org/docs/messages/opening-an-issue
npm notice 
npm notice New minor version of npm available! 10.2.4 -> 10.4.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.4.0>
npm notice Run `npm install -g npm@10.4.0` to update!
npm notice

Which area(s) are affected? (Select all that apply)

CLI (create-next-app), Standalone mode (output: "standalone")

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

It complains about find-up... maybe the issue has to do with some bug in it?

@x-yuri x-yuri added the bug Issue was opened via the bug report template. label Feb 27, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`. labels Feb 27, 2024
@x-yuri x-yuri changed the title npm run build doesn't work at filesystem root npm run build doesn't work at a filesystem root Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`.
Projects
None yet
Development

No branches or pull requests

1 participant