#node.js #reactjs #next.js #vercel
Вопрос:
Я разворачивал свой next.js приложение, как обычно, на верселе и застряло на этой ошибке. Сначала я подумал, что это связано с тем, что момент использовался на статических страницах, удален, но все равно не работал, затем я удалил все изображения, импортированные на определенных страницах, и указал общедоступный путь в src изображений, но сборка снова не удалась. Журналы являются:
08:08:17.998 [4/4] Building fresh packages... 08:08:26.082 error /vercel/path0/node_modules/mozjpeg: Command failed. 08:08:26.082 Exit code: 1 08:08:26.082 Command: node lib/install.js 08:08:26.082 Arguments: 08:08:26.082 Directory: /vercel/path0/node_modules/mozjpeg 08:08:26.082 Output: 08:08:26.082 Command failed: /vercel/path0/node_modules/mozjpeg/vendor/cjpeg -version 08:08:26.082 /vercel/path0/node_modules/mozjpeg/vendor/cjpeg: /lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /vercel/path0/node_modules/mozjpeg/vendor/cjpeg) 08:08:26.082 mozjpeg pre-build test failed 08:08:26.083 compiling from source 08:08:26.083 Error: Command failed: /bin/sh -c ./configure --enable-static --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/vercel/path0/node_modules/mozjpeg/vendor" --bindir="/vercel/path0/node_modules/mozjpeg/vendor" --libdir="/vercel/path0/node_modules/mozjpeg/vendor" 08:08:26.083 ./configure: line 8028: /usr/bin/file: No such file or directory 08:08:26.083 configure: error: no nasm (Netwide Assembler) found
Мой пакет.json (я запустил ncu-u на этом самом последнем):
"scripts": { "dev": "next dev", "build": "next build", "start": "next start", "postbuild": "next-sitemap --config next-sitemap.config.js", "serve": "next serve" }, "dependencies": { "axios": "^0.23.0", "cheerio": "^1.0.0-rc.10", "clsx": "^1.1.1", "formik": "^2.2.9", "google-translate-api-browser": "^1.1.71", "imagemin-mozjpeg": "^9.0.0", "imagemin-optipng": "^8.0.0", "lazysizes": "^5.3.2", "leaflet": "^1.7.1", "lodash.debounce": "^4.0.8", "lqip-loader": "^2.2.1", "moment": "^2.29.1", "next": "11.1.2", "next-compose-plugins": "^2.2.1", "next-optimized-images": "^2.6.2", "next-sitemap": "^1.6.184", "next-themes": "^0.0.15", "preact": "^10.5.15", "react": "17.0.2", "react-cool-onclickoutside": "^1.7.0", "react-dom": "17.0.2", "react-leaflet": "^3.2.2", "react-markdown": "^7.0.1", "react-optimized-image": "^0.4.1", "react-syntax-highlighter": "^15.4.4", "react-toggle-dark-mode": "^1.0.4", "swr": "^1.0.1", "typeface-merriweather": "^1.1.13", "typeface-open-sans": "^1.1.13", "webp-loader": "^0.6.0" }, "devDependencies": { "@tailwindcss/typography": "^0.4.1", "autoprefixer": "^10.3.7", "gray-matter": "^4.0.3", "postcss": "^8.3.9", "tailwindcss": "^2.2.17" },
next.config.js
const withPlugins = require("next-compose-plugins"); const optimizedImages = require("next-optimized-images"); const nextConfig = { webpack: (config, { isServer }) =gt; { if (isServer) { require("./scripts/sitemap-common"); } return config; }, webpack: (config, { dev, isServer }) =gt; { // Replace React with Preact only in client production build if (!dev amp;amp; !isServer) { Object.assign(config.resolve.alias, { react: "preact/compat", "react-dom/test-utils": "preact/test-utils", "react-dom": "preact/compat", }); } return config; }, }; module.exports = withPlugins( [ optimizedImages, { domains: ["mars.nasa.gov", "www.nasaspaceflight.com"], }, ], nextConfig );
import Link from "next/link"; import ReactMarkdown from "react-markdown"; import { SEO } from "@components/common"; import { getPostBySlug, getPostsSlugs } from "@utils/posts"; function Post({ post, slug, frontmatter, nextPost, previousPost }) { return ( lt;gt; lt;SEO slug={slug} title={frontmatter.title} imageUrl={`${slug}.jpg` || `${slug}.png`} description={frontmatter.description} /gt; lt;article className="px-4 max-w-screen-2xl"gt; lt;header className="mb-8 mt-8"gt; lt;h1 className="mb-2 text-4xl font-black leading-none font-display"gt; {frontmatter.title} lt;/h1gt;{" "} lt;time datetime={frontmatter.date} className="text-sm"gt; {frontmatter.date} lt;/timegt; lt;/headergt; lt;ReactMarkdown className="mb-4 prose lg:prose-lg dark:prose-dark" escapeHtml={false} source={post.content} /gt; lt;hr className="mt-4" /gt; lt;/articlegt; lt;nav className="flex px-4 flex-wrap justify-between mb-10"gt; {previousPost ? ( lt;Link href={"/post/[slug]"} as={`/post/${previousPost.slug}`}gt; lt;a className="text-lg font-bold"gt; ← {previousPost.frontmatter.title} lt;/agt; lt;/Linkgt; ) : ( lt;div /gt; )} {nextPost ? ( lt;Link href={"/post/[slug]"} as={`/post/${nextPost.slug}`}gt; lt;a className="text-lg font-bold"gt;{nextPost.frontmatter.title} →lt;/agt; lt;/Linkgt; ) : ( lt;div /gt; )} lt;/navgt; lt;/gt; ); } export async function getStaticPaths() { const paths = getPostsSlugs(); return { paths, fallback: false, }; } export async function getStaticProps({ params: { slug } }) { const postData = getPostBySlug(slug); if (!postData.previousPost) { postData.previousPost = null; } if (!postData.nextPost) { postData.nextPost = null; } return { props: postData }; } export default Post;
Если вам нужна дополнительная информация, пожалуйста, скажите мне, что я буду очень признателен за любую помощь
Комментарии:
1. Можете ли вы построить Next.js приложение (
npm run build
) успешно локально?2. После сборки в последней строке было просто написано, что загружен файл env из… в процессе разработки вместо этого я получаю эту ошибку
Unhandled Runtime Error TypeError: Cannot read properties of undefined (reading 'call')
@juliomalves, я также предоставил следующий файл.config