Open Adelrisk opened 1 year ago
What is not a feasible workaround: individually unplugging the missing dependencies and copying them into the standalone directory. Such as:
# After running `yarn next build` as declared above, copy in the source of `styled-jsx`
# Add styled-jsx to the project (otherwise yarn will not unplug it)
yarn add styled-jsx
# Create unzipped copy of source of the dependency
yarn unplug styled-jsx
# Copy the dependency into the standalone application
cp -r .yarn/unplugged/styled-jsx*/node_modules .next/standalone
Repeat for: react
, @swr/helpers
, @next/env
, react-dom
The server will run, but opening the page with the browser looks like this:
Listening on port 3000 url: http://localhost:3000
Error: Cannot find module 'next/dist/server/get-page-files.js'
Require stack:
- /home/workdir/next-docker-problem/.next/standalone/.next/server/pages/_document.js
- /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/server/require.js
- /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/server/next-server.js
- /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/server/next.js
- /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/server/lib/render-server.js
- /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/compiled/jest-worker/processChild.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at /home/workdir/next-docker-problem/.next/standalone/node_modules/next/dist/server/require-hook.js:180:36
at Module._load (node:internal/modules/cjs/loader:885:27)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at 140 (/home/workdir/next-docker-problem/.next/standalone/.next/server/pages/_document.js:916:18)
at __webpack_require__ (/home/workdir/next-docker-problem/.next/standalone/.next/server/webpack-runtime.js:25:42)
at 632 (/home/workdir/next-docker-problem/.next/standalone/.next/server/pages/_document.js:44:23)
at __webpack_require__ (/home/workdir/next-docker-problem/.next/standalone/.next/server/webpack-runtime.js:25:42)
at 35 (/home/workdir/next-docker-problem/.next/standalone/.next/server/pages/_document.js:907:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [
I have the same issue event tho I'm not using styled-jsx
on my project.
I'm using a NX monorepo, pnpm and the standalone build for next. The build and local dev work but this error arise as soon as my app is deployed on vercel:
Cannot find module 'styled-jsx/style'
Require stack:
- /var/task/node_modules/.pnpm/next@13.4.5_@babel+core@7.22.5_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/require-hook.js
- /var/task/node_modules/.pnpm/next@13.4.5_@babel+core@7.22.5_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/next-server.js
- /var/task/apps/web/___next_launcher.cjs
Did you forget to add it to "dependencies" in `package.json`?
RequestId: 315de20f-f82b-4636-8f5d-12ea73a18f69 Error: Runtime exited without providing a reason
Runtime.ExitError
My build should be using swc also as I don't have any .babelrc
on my next app (other libraries on my monorepo use babel tho).
Any pointer of why it's happening ?
Here is my package.json
:
{
"name": "offline",
"version": "0.0.0",
"scripts": {
"nx": "nx",
"serve": "nx run-many --target=serve --all",
"start": "npm-run-all --parallel serve docker:services",
"lint": "nx workspace-lint && nx lint",
"format": "nx format:write",
"format:write": "nx format:write",
"format:check": "nx format:check",
"all:test": "pnpm docker:test && nx run-many --target=test --all",
"all:e2e": "nx run-many --target=e2e --all",
"update": "nx migrate latest && pnpm install && nx migrate --run-migrations",
"dep-graph": "nx dep-graph",
"nx-graph-static": "nx graph --file=static/nx-graph/index.html",
"help": "nx help",
"graphql-codegen": "nx run web:gql",
"thegraph-build": "graphclient build --dir libs/client/gql/thegraph/src",
"thegraph": "graphclient",
"affected:build": "nx affected:build",
"affected:e2e": "pnpm docker:services && nx affected:e2e",
"affected:test": "pnpm docker:test && nx affected:test && pnpm affected:test-prisma && pnpm affected:test-hasura",
"affected:test-prisma": "nx affected --target=test-prisma",
"affected:test-hasura": "nx affected --target=test-hasura",
"affected:lint": "nx affected:lint",
"affected:dep-graph": "nx affected:dep-graph",
"docker:services": "docker-compose --env-file .env.local up -d prisma-db && pnpm prisma:dev:deploy && docker-compose --env-file .env.local up -d",
"docker:test": "docker-compose -f tools/test/docker-compose.yml --env-file tools/test/.env.test.jest up -d prisma-test-db && pnpm prisma:test:deploy && docker-compose -f tools/test/docker-compose.yml --env-file tools/test/.env.test.jest up -d",
"docker:build": "docker-compose --env-file .env.local build",
"docker:stop": "docker-compose --env-file .env.local stop",
"docker:hasura-engine-logs": "docker-compose -f docker-compose.yaml --env-file .env.local logs -f hasura-engine",
"docker:hasura-console-logs": "docker-compose -f docker-compose.yaml --env-file .env.local logs -f hasura-console",
"docker:hasura-test-logs": "docker-compose -f tools/test/docker-compose.yml --env-file tools/test/.env.test.jest logs -f hasura-engine-test",
"prepare": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\"",
"cypress": "cypress",
"analyze:web": "cross-env ANALYZE=true nx build web",
"build-storybook:ui": "nx run ui-components:build-storybook",
"build-storybook:web": "nx run web:build-storybook",
"prisma:dev:deploy": "dotenv -e .env.local -- prisma migrate dev",
"prisma-db:dev:rm": "docker-compose --env-file .env.local rm prisma-db -s -f -v",
"prisma-db:dev:up": "docker-compose --env-file .env.local up prisma-db -d",
"prisma-db:dev:start": "pnpm prisma-db:dev:up && sleep 1 && pnpm prisma:dev:deploy",
"prisma-db:dev:restart": "pnpm prisma-db:dev:rm && pnpm prisma-db:dev:start",
"prisma:test:deploy": "dotenv -e tools/test/.env.test.jest -- prisma migrate dev",
"prisma-db:test:rm": "docker-compose -f tools/test/docker-compose.yml --env-file tools/test/.env.test.jest rm prisma_test_db -s -f -v",
"prisma-db:test:up": "docker-compose -f tools/test/docker-compose.yml --env-file tools/test/.env.test.jest up prisma_test_db -d",
"prisma-db:test:restart": "pnpm prisma-db:test:rm && pnpm prisma-db:test:up && sleep 1 && pnpm prisma:test:deploy",
"nest:dev:start": "nx run nestjs-server:serve",
"nest:e2e": "start-server-and-test e2e:server 'http://localhost:3333/api' e2e:test",
"e2e:test": "nx run nestjs-server-e2e:e2e",
"e2e:server": "nx run nestjs-server:serve --skip-nx-cache",
"vercel-build": "npm i -g node-gyp"
},
"private": true,
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@formkit/auto-animate": "1.0.0-beta.6",
"@nestjs/axios": "^0.1.1",
"@nestjs/common": "^9.4.3",
"@nestjs/config": "^2.3.3",
"@nestjs/core": "^9.4.3",
"@nestjs/jwt": "^9.0.0",
"@nestjs/microservices": "^9.4.3",
"@nestjs/platform-express": "^9.4.3",
"@nestjs/schedule": "^2.2.3",
"@nestjs/terminus": "^9.2.2",
"@next/font": "^13.4.5",
"@ntegral/nestjs-sentry": "^4.0.0",
"@prisma/client": "^4.15.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.4",
"@radix-ui/react-aspect-ratio": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.3",
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@safe-global/api-kit": "^1.1.0",
"@safe-global/protocol-kit": "^1.0.1",
"@safe-global/safe-react-components": "^2.0.5",
"@sentry/nextjs": "^7.54.0",
"@sentry/node": "^7.54.0",
"@sentry/tracing": "^7.54.0",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"@tanstack/query-core": "^4.29.11",
"@tanstack/react-query": "^4.29.12",
"@types/cache-manager": "^4.0.2",
"@types/cache-manager-redis-store": "^2.0.1",
"@vercel/analytics": "^0.1.11",
"@web3auth/ui": "^5.2.0",
"@xstate/react": "^3.2.2",
"alchemy-sdk": "^2.9.0",
"autoprefixer": "^10.4.14",
"cache-manager": "^5.2.2",
"cache-manager-redis-store": "^3.0.1",
"chalk": "4.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
"coingecko-api-v3": "0.0.13",
"core-js": "^3.31.0",
"crypto-js": "^4.1.1",
"css-loader": "^6.8.1",
"date-fns": "^2.30.0",
"dotenv": "^16.1.4",
"ethers": "^5.7.2",
"express": "^4.18.2",
"framer-motion": "^6.5.1",
"graphql-ws": "^5.13.1",
"http-status-codes": "^2.2.0",
"immer": "^10.0.2",
"install": "^0.13.0",
"ioredis": "^5.3.2",
"joi": "^17.9.2",
"loglevel": "^1.8.1",
"loglevel-plugin-prefix": "^0.8.4",
"lucide-react": "^0.125.0",
"next": "13.4.5",
"next-auth": "4.22.1",
"next-intl": "2.15.0-beta.5",
"next-seo": "^5.15.0",
"next-sitemap": "^3.1.55",
"next-themes": "^0.2.1",
"node-cache-manager": "^1.2.0",
"node-fetch": "^2.6.11",
"nodemailer": "^6.9.3",
"openid-client": "^5.4.2",
"postcss": "^8.4.24",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.3.3",
"prisma": "^4.15.0",
"react": "^18.2.0",
"react-day-picker": "^8.7.1",
"react-dom": "^18.2.0",
"react-hook-form": "^7.44.3",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.9.0",
"react-use": "^17.4.0",
"reflect-metadata": "^0.1.13",
"regenerator-runtime": "0.13.7",
"remeda": "^1.19.0",
"rxjs": "^7.8.1",
"siwe": "^2.1.4",
"tailwind-merge": "^1.13.1",
"tailwindcss": "^3.3.2",
"tailwindcss-animate": "^1.0.6",
"tslib": "^2.5.3",
"uuid": "^8.3.2",
"web3": "^1.10.0",
"websocket": "^1.0.34",
"zod": "^3.21.4",
"zustand": "^4.3.8"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.22.5",
"@cypress/code-coverage": "^3.10.7",
"@depay/web3-mock-evm": "^14.11.1",
"@faker-js/faker": "^7.6.0",
"@graphprotocol/client-cli": "^2.2.22",
"@graphql-codegen/add": "^3.2.3",
"@graphql-codegen/cli": "^2.16.5",
"@graphql-codegen/client-preset": "^1.3.0",
"@graphql-codegen/hasura-allow-list": "^2.0.0",
"@graphql-codegen/introspection": "^2.2.3",
"@graphql-codegen/schema-ast": "^2.6.1",
"@graphql-codegen/typescript": "^2.8.8",
"@graphql-codegen/typescript-generic-sdk": "^3.1.0",
"@graphql-codegen/typescript-operations": "^2.5.13",
"@graphql-codegen/typescript-react-query": "^4.1.0",
"@graphql-eslint/eslint-plugin": "^3.19.1",
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.4.3",
"@next/bundle-analyzer": "^13.4.5",
"@nx/cypress": "16.3.2",
"@nx/devkit": "16.3.2",
"@nx/eslint-plugin": "16.3.2",
"@nx/eslint-plugin-nx": "16.0.0-beta.1",
"@nx/jest": "16.3.2",
"@nx/js": "16.3.2",
"@nx/linter": "16.3.2",
"@nx/nest": "16.3.2",
"@nx/next": "16.3.2",
"@nx/node": "16.3.2",
"@nx/plugin": "16.3.2",
"@nx/react": "16.3.2",
"@nx/rollup": "16.3.2",
"@nx/storybook": "16.3.2",
"@nx/web": "16.3.2",
"@nx/webpack": "16.3.2",
"@nx/workspace": "16.3.2",
"@rollup/plugin-url": "^7.0.0",
"@safe-global/auth-kit": "^1.0.0",
"@storybook/addon-a11y": "7.0.17",
"@storybook/addon-essentials": "7.0.17",
"@storybook/addon-interactions": "7.0.17",
"@storybook/addon-mdx-gfm": "7.0.17",
"@storybook/addon-styling": "1.0.8",
"@storybook/builder-webpack5": "7.0.17",
"@storybook/core-common": "7.0.17",
"@storybook/core-server": "7.0.17",
"@storybook/jest": "0.1.0",
"@storybook/nextjs": "7.0.17",
"@storybook/react": "7.0.17",
"@storybook/react-webpack5": "7.0.17",
"@storybook/test-runner": "0.10.0",
"@storybook/testing-library": "0.1.0",
"@storybook/theming": "7.0.17",
"@svgr/rollup": "^6.5.1",
"@svgr/webpack": "^6.5.1",
"@swc-node/register": "^1.6.5",
"@swc/cli": "~0.1.62",
"@swc/core": "^1.3.62",
"@swc/jest": "0.2.20",
"@tanstack/react-query-devtools": "^4.29.12",
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/cron": "^2.0.1",
"@types/jest": "29.5.0",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "18.14.2",
"@types/node-fetch": "^2.6.4",
"@types/pg": "^8.10.2",
"@types/react": "^18.2.11",
"@types/react-dom": "^18.2.4",
"@types/testing-library__jest-dom": "^5.14.6",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@web3auth/base": "^5.2.0",
"@web3auth/modal": "^5.2.1",
"@web3auth/openlogin-adapter": "^5.2.1",
"axe-playwright": "^1.2.3",
"babel-jest": "^29.5.0",
"babel-loader": "^9.1.2",
"chromatic": "^6.18.2",
"cross-env": "^7.0.3",
"cypress": "^12.14.0",
"dotenv-cli": "^6.0.0",
"encoding": "^0.1.13",
"eslint": "~8.15.0",
"eslint-config-next": "13.4.5",
"eslint-config-prettier": "8.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-sonarjs": "^0.16.0",
"eslint-plugin-storybook": "^0.6.12",
"eslint-plugin-tailwindcss": "^3.12.1",
"eth-testing": "^1.14.0",
"flowbite-typography": "^1.0.3",
"graphql": "^16.6.0",
"graphql-config": "^4.5.0",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jsonc-eslint-parser": "^2.3.0",
"jsonwebtoken": "^9.0.0",
"lint-staged": "^13.2.2",
"msw": "^1.2.2",
"next-router-mock": "^0.9.6",
"npm-run-all": "^4.1.5",
"nx": "16.3.2",
"nx-cloud": "16.0.5",
"pactum": "^3.4.1",
"pg": "^8.11.0",
"prettier": "^2.8.8",
"prettier-plugin-prisma": "^4.13.0",
"react-refresh": "^0.10.0",
"react-test-renderer": "18.2.0",
"start-server-and-test": "^1.15.4",
"storybook-addon-swc": "^1.2.0",
"storybook-dark-mode": "^3.0.0",
"swc-loader": "0.1.15",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "~5.1.3",
"url-loader": "^4.1.1"
},
"packageManager": "pnpm@8.5.1",
"engines": {
"node": ">=16.0.0",
"pnpm": ">=7"
},
"_id": "offline@0.0.0",
"msw": {
"workerDirectory": "apps/nestjs-server/src"
}
}
My apps/web/next.config.js
:
/* eslint-disable @typescript-eslint/no-var-requires */
const { withNx } = require('@nx/next');
const path = require('path');
const { withSentryConfig } = require('@sentry/nextjs');
/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
*
* @template {import('next').NextConfig} T
* @param {T} nextI18n - A generic parameter that flows through to the return type
* @constraint {{import('next').NextConfig}}
*/
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const withNextIntl = require('next-intl/plugin')();
const SENTRY_DSN = process.env.SENTRY_AUTH_TOKEN
? null
: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
compiler: {
removeConsole: process.env.NODE_ENV === 'production',
},
/* could improve performance in dev but @ui components no organized like that.
See that as ref: https://github.com/knitkode/koine/blob/3046607d655a3cfa1e3b3438f1aef168fbdc6ad5/packages/next/config/index.ts#L251
https://nextjs.org/blog/next-13-1#import-resolution-for-smaller-bundles
And this thread n
+ this article: https://medium.com/@yashashr/next-js-optimization-for-better-performance-part-1-material-ui-mui-configs-plugins-6fdc48a4e984
*/
// modularizeImports: {
// '@ui/components/?(((\\w*)?/?)*)': {
// transform: '@ui/components/{{ matches.[1] }}/{{member}}',
// },
// },
transpilePackages: ['@ui/components', '@ui/theme', '@ui/icons', 'styled-jsx'],
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'picsum.photos',
port: '',
pathname: '/seed/hero/**',
},
],
},
// optimize build with vercel nft (node file tracing) https://nextjs.org/docs/advanced-features/output-file-tracing
// outputFileTracingRoot needed for monorepo
output: 'standalone',
experimental: {
outputFileTracingRoot: path.join(__dirname, '../../'),
outputFileTracingExcludes: {
'*': [
'./**/@swc/core-linux-x64-gnu*',
'./**/@swc/core-linux-x64-musl*',
'./**/@esbuild*',
'./**/webpack*',
'./**/rollup*',
'./**/terser*',
'./**/sharp*',
],
},
serverActions: true,
appDir: true,
typedRoutes: false, // no solution found to get it working with nx monorepo (not accessible from external libs like feature)
},
};
const sentryWebpackPluginOptions = {
// Additional config options for the Sentry Webpack plugin. Keep in mind that
// the following options are set automatically, and overriding them is not
// recommended:
// release, url, org, project, authToken, configFile, stripPrefix,
// urlPrefix, include, ignore
dryRun: !SENTRY_DSN,
hideSourceMaps: true,
silent: true, // Suppresses all logs
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
};
module.exports = async (phase, context) => {
const addNx = withNx({
...nextConfig,
});
let config = await addNx(phase);
// // TODO, set back after fix for: Module not found: Can't resolve '@sentry/utils/esm/buildPolyfills'
// config = await withSentryConfig(config, sentryWebpackPluginOptions);
config = await withBundleAnalyzer(config);
config = await withNextIntl(config);
return config;
};
My apps/web/project.json
:
{
"name": "web",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/web",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/next:build",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"root": "apps/web",
"outputPath": "apps/web/dist",
"postcssConfig": "apps/web/postcss.config.js"
},
"assets": [
{
"input": "libs/ui/shared/src/assets",
"glob": "**/*",
"output": "assets"
}
],
"configurations": {
"development": {
"outputPath": "apps/web"
},
"production": {}
}
},
"serve": {
"executor": "@nx/next:server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "web:build",
"hmr": true,
"port": 8888,
"dev": true,
"assets": [
{
"input": "libs/ui/shared/src/assets",
"glob": "**/*",
"output": "assets"
}
]
},
"configurations": {
"development": {
"buildTarget": "web:build:development",
"dev": true
},
"production": {
"buildTarget": "web:build:production",
"dev": false
}
}
},
"is-services-launched": {
"executor": "nx:run-commands",
"options": {
"commands": ["node tools/test/isServicesLaunched.js"],
"readyWhen": "Services ready"
}
},
"serve-e2e": {
"executor": "nx:run-commands",
"options": {
"commands": ["nx is-services-launched web", "nx serve web"],
"readyWhen": "Services ready"
}
},
"export": {
"executor": "@nx/next:export",
"options": {
"buildTarget": "web:build:production"
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/web"],
"options": {
"jestConfig": "apps/web/jest.config.ts",
"passWithNoTests": true
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/web/**/*.{ts,tsx,js,jsx,gql,graphql}"]
}
},
"gql": {
"executor": "nx:run-commands",
"options": {
"commands": [
{
"command": "npx graphql-codegen --config codegen.yml -r dotenv/config -e .env.local "
}
]
}
},
"storybook": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 4401,
"quiet": true,
"configDir": "apps/web/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"build-storybook": {
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"configDir": "apps/web/.storybook",
"outputDir": "dist/storybook/web",
"webpackStatsJson": true
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"test-storybook": {
"executor": "nx:run-commands",
"options": {
"command": "test-storybook -c apps/web/.storybook --url=http://localhost:4401"
}
}
},
"tags": []
}
And my settings on vercel:
Any help would be greatly appreciated !
Hello, I have a similar issue with the latest version of nextjs v13.4.5: Error: Cannot find module 'next/dist/compiled/jest-worker'
The lib is not included in .next/standalone/node-modules when builded with : npm ci
for production dependencies only.
I have a similar issue in standalone mode :
node:internal/modules/cjs/loader:1080
throw err;
^
Error: Cannot find module 'next/dist/server/lib/start-server'
Require stack:
- /usr/src/app/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/usr/src/app/server.js:4:25)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/usr/src/app/server.js' ]
}
The file is present in my local node_modules
but not in .next/standalone/node_modules
I have a similar issue in standalone mode :
node:internal/modules/cjs/loader:1080 throw err; ^ Error: Cannot find module 'next/dist/server/lib/start-server' Require stack: - /usr/src/app/server.js at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15) at Module._load (node:internal/modules/cjs/loader:922:27) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:110:18) at Object.<anonymous> (/usr/src/app/server.js:4:25) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/src/app/server.js' ] }
The file is present in my local
node_modules
but not in.next/standalone/node_modules
I hit the same thing following the "with-docker" example as described in https://nextjs.org/docs/pages/building-your-application/deploying#docker-image.
I was able to solve it by also including the .dockerignore
from the repo which specifically excludes the .next
and node_modules
directories. Otherwise, any local directories will be aggressively passed in due to the COPY directive.
(next 13.5.1)
I build with standalone
and copy the relevant assets to docker build, occurring the same error: Error: Cannot find module 'styled-jsx/package.json
node:internal/modules/cjs/loader:1051
throw err;
^
Error: Cannot find module 'styled-jsx/package.json'
Require stack:
- /app/node_modules/next/dist/server/require-hook.js
- /app/node_modules/next/dist/server/next.js
- /app/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
at resolve (node:internal/modules/helpers:136:19)
at Object.<anonymous> (/app/node_modules/next/dist/server/require-hook.js:38:32)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at Object.<anonymous> (/app/node_modules/next/dist/server/next.js:25:1) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/app/node_modules/next/dist/server/require-hook.js',
'/app/node_modules/next/dist/server/next.js',
'/app/server.js'
]
}
The procedures I followed:
standalone
mode and specify distDir: 'build'
in next.config.mjs
pnpm next build
docker
folder
cp -r public build/standalone/* Dockerfile docker
The simple Dockerfile (just copy assets in docker folder and start server.js):
# syntax=docker/dockerfile:1
FROM node:20.6-slim
WORKDIR /app
COPY . .
ENV PORT 8000 EXPOSE 8000
CMD ["node","server.js"]
3. Docker build (cd above `docker` folder) and run:
docker buildx build -t demo --load . docker run -it --rm -p 8000:3000 --name demo demo
4. Access http://localhost:8000 . The above error occurs and container stop.
I took a look at the error file `build/standalone/node_modules/next/dist/server/require-hook.js` and found the source:
const defaultOverrides = { "styled-jsx": path.dirname(resolve("styled-jsx/package.json")), "styled-jsx/style": resolve("styled-jsx/style") };
It might be related to pnpm module path. I don't know.
I have a similar issue, both with pnpm and yarn. Haven't tried with npm.
1.883 yarn run v1.22.19
2.088 $ next build
7.920 Creating an optimized production build ...
58.53 Failed to compile.
58.53
58.54 src/app/[locale]/layout.tsx
58.54 An error occured in `next/font`.
58.54
58.54 Error: Cannot find module 'autoprefixer'
58.54 Require stack:
58.54 - /app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js
58.54 - /app/node_modules/next/dist/build/webpack/config/blocks/css/index.js
58.54 - /app/node_modules/next/dist/build/webpack/config/index.js
58.54 - /app/node_modules/next/dist/build/webpack-config.js
58.54 - /app/node_modules/next/dist/build/webpack/plugins/next-trace-entrypoints-plugin.js
58.54 - /app/node_modules/next/dist/build/collect-build-traces.js
58.54 - /app/node_modules/next/dist/build/index.js
58.54 - /app/node_modules/next/dist/cli/next-build.js
58.54 - /app/node_modules/next/dist/lib/commands.js
58.54 - /app/node_modules/next/dist/bin/next
58.54 at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
58.54 at /app/node_modules/next/dist/server/require-hook.js:54:36
58.54 at Function.resolve (node:internal/modules/cjs/helpers:125:19)
58.54 at loadPlugin (/app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:49:32)
58.54 at /app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:157:56
58.54 at Array.map (<anonymous>)
58.54 at getPostCssPlugins (/app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:157:47)
58.54 at async /app/node_modules/next/dist/build/webpack/config/blocks/css/index.js:124:36
58.54 at async /app/node_modules/next/dist/build/webpack/loaders/next-font-loader/index.js:86:33
58.54 at async Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:105:20)
58.54
58.54 src/app/[locale]/layout.tsx
58.54 An error occured in `next/font`.
58.54
58.54 Error: Cannot find module 'autoprefixer'
58.54 Require stack:
58.54 - /app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js
58.54 - /app/node_modules/next/dist/build/webpack/config/blocks/css/index.js
58.54 - /app/node_modules/next/dist/build/webpack/config/index.js
58.54 - /app/node_modules/next/dist/build/webpack-config.js
58.54 - /app/node_modules/next/dist/build/webpack/plugins/next-trace-entrypoints-plugin.js
58.54 - /app/node_modules/next/dist/build/collect-build-traces.js
58.54 - /app/node_modules/next/dist/build/index.js
58.54 - /app/node_modules/next/dist/cli/next-build.js
58.54 - /app/node_modules/next/dist/lib/commands.js
58.54 - /app/node_modules/next/dist/bin/next
58.54 at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
58.54 at /app/node_modules/next/dist/server/require-hook.js:54:36
58.54 at Function.resolve (node:internal/modules/cjs/helpers:125:19)
58.54 at loadPlugin (/app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:49:32)
58.54 at /app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:157:56
58.54 at Array.map (<anonymous>)
58.54 at getPostCssPlugins (/app/node_modules/next/dist/build/webpack/config/blocks/css/plugins.js:157:47)
58.54 at async /app/node_modules/next/dist/build/webpack/config/blocks/css/index.js:124:36
58.54 at async /app/node_modules/next/dist/build/webpack/loaders/next-font-loader/index.js:86:33
58.54 at async Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:105:20)
58.54
58.55
58.56 > Build failed because of webpack errors
58.72 error Command failed with exit code 1.
58.72 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Trying to run a standalone build with next@13.5.4. Any news?
pnpm uses sym linking when creating the modules so you might run into issues like this of missing modules.
Either follow this https://pnpm.io/docker
or use node-linker=hoisted
in .npmrc
to return it to a flat structure no link https://pnpm.io/npmrc#node-linker
I assume yarn has a similar thing
I am having the same issue while trying to use @newrelic/next dependency.
Seems this issue still exists. It's styled-jsx
for me. Next v14.1.0
To give more info, it's not that it doesn't exist, it's that some of it is missing:
Local:
ls node_modules/styled-jsx
total 176
drwxr-xr-x@ 19 root root 608B Jan 27 10:02 ./
drwxr-xr-x@ 794 root root 25K Jan 27 10:02 ../
-rw-r--r--@ 1 root root 68B Jan 27 10:02 babel-test.js
-rw-r--r--@ 1 root root 49B Jan 27 10:02 babel.js
-rw-r--r--@ 1 root root 475B Jan 27 10:02 css.d.ts
-rw-r--r--@ 1 root root 469B Jan 27 10:02 css.js
drwxr-xr-x@ 5 root root 160B Jan 27 10:02 dist/
-rw-r--r--@ 1 root root 160B Jan 27 10:02 global.d.ts
-rw-r--r--@ 1 root root 645B Jan 27 10:02 index.d.ts
-rw-r--r--@ 1 root root 41B Jan 27 10:02 index.js
drwxr-xr-x@ 4 root root 128B Jan 27 10:02 lib/
-rw-r--r--@ 1 root root 1.1K Jan 27 10:02 license.md
-rw-r--r--@ 1 root root 224B Jan 27 10:02 macro.d.ts
-rw-r--r--@ 1 root root 49B Jan 27 10:02 macro.js
-rw-r--r--@ 1 root root 3.1K Jan 27 10:02 package.json
-rw-r--r--@ 1 root root 31K Jan 27 10:02 readme.md
-rw-r--r--@ 1 root root 91B Jan 27 10:02 style.d.ts
-rw-r--r--@ 1 root root 47B Jan 27 10:02 style.js
-rw-r--r--@ 1 root root 65B Jan 27 10:02 webpack.js
In container built with the typical Dockerfile:
ls -l node_modules/styled-jsx/
total 12
drwxr-xr-x 3 root root 4096 Jan 27 20:07 dist
-rw-r--r-- 1 root root 41 Jan 27 20:07 index.js
-rw-r--r-- 1 root root 3142 Jan 27 20:07 package.json
Yeah, this issue still exists. We're getting it as well on 13.5.2.
I think the devs have enough information by now. Can everyone think twice before bumping, so that we don't end up with an ocean of "this happens to me on ..." replies? Thanks.
I think the devs have enough information by now. Can everyone think twice before bumping, so that we don't end up with an ocean of "this happens to me on ..." replies? Thanks.
Are they doing anything about it? Seems like this has been a thing for more than a year.
@0xbid Just as a reminder, Next.js is a commercial project by Vercel, which is a company that offers web hosting. I don't think this is at the top of their priorities since it would make self-hosting much easier, reducing their profit. :-/
I tried to reproduce the issue, but it doesn't build:
$ git clone https://github.com/Adelrisk/reproducer_nextjs_standalone_require
$ cd reproducer_nextjs_standalone_require
$ docker build -t i .
...
#12 [builder 3/6] COPY package.json yarn.lock .yarnrc.yml ./
#12 ERROR: failed to calculate checksum of ref 4UIH:CJ45:IO4E:2I6A:USR5:G3NC:EFF7:MB6F:ZIHU:NJFB:DBD6:2HU7::lr0ca4fw822rvcavc4t0pknms: "/.yarnrc.yml": not found
#13 [deps 6/7] COPY package.json yarn.lock .yarnrc.yml ./
#13 ERROR: failed to calculate checksum of ref 4UIH:CJ45:IO4E:2I6A:USR5:G3NC:EFF7:MB6F:ZIHU:NJFB:DBD6:2HU7::lr0ca4fw822rvcavc4t0pknms: "/.yarnrc.yml": not found
#14 [deps 4/7] COPY .yarn ./.yarn/
#14 ERROR: failed to calculate checksum of ref 4UIH:CJ45:IO4E:2I6A:USR5:G3NC:EFF7:MB6F:ZIHU:NJFB:DBD6:2HU7::lr0ca4fw822rvcavc4t0pknms: "/.yarn": not found
#15 [deps 3/7] RUN corepack enable
#15 DONE 0.5s
------
> [deps 4/7] COPY .yarn ./.yarn/:
------
------
> [deps 6/7] COPY package.json yarn.lock .yarnrc.yml ./:
------
------
> [builder 3/6] COPY package.json yarn.lock .yarnrc.yml ./:
------
Dockerfile:25
--------------------
23 |
24 | COPY --from=deps /app/.yarn/ ./.yarn
25 | >>> COPY package.json yarn.lock .yarnrc.yml ./
26 | COPY . ./
27 | # This will do the trick, use the corresponding env file for each environment.
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 4UIH:CJ45:IO4E:2I6A:USR5:G3NC:EFF7:MB6F:ZIHU:NJFB:DBD6:2HU7::lr0ca4fw822rvcavc4t0pknms: "/.yarnrc.yml": not found
I copied the Dockerfile
from the issue, and still doesn't build:
$ docker build -t i .
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 1.48kB done
#1 DONE 0.0s
Dockerfile:48
--------------------
46 | COPY --from=builder --chown=nextjs:nodejs /app/public* ./public/
47 | COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone/.yarn/cache/*/node_modules* ./node_modules/
48 | >>> /*/node_modules* ./node_modules/
49 | COPY --from=builder --chown=nextjs:nodejs /app/.next/static* ./.next/static
50 |
--------------------
ERROR: failed to solve: dockerfile parse error on line 48: unknown instruction: /*/node_modules*
And to be frank, it doesn't look like MRE.
I myself ran into another issue. Which looks like yours a bit, but likely isn't.
COPY --from=builder /app/node_modules ./node_modules
fix the issue for me
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
https://github.com/Adelrisk/reproducer_nextjs_standalone_require
To Reproduce
Prepare a project
Prepare without the reproducer
Prepare with the reproducer
Reproduce the problem
Without docker:
With docker:
Add the following file to the directory:
Describe the Bug
One-time error with latest (not canary)
When I started to document the steps to reproduce the error, it was identical to https://github.com/vercel/next.js/issues/48173
However, after using canary, I couldn't reproduce the error, even after downgrading.
Error with canary/latest version
The error with docker
The error without docker
Expected Behavior
I would expect the MVP app to run without problems.
Additionally, I notice that the script
node_modules/next/dist/server/require-hook.js
attempts to require many other (not available) third party dependencies:Once I faked all these dependencies, additional require calls fail because these dependencies are missing:
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
node server.js