next.js 由于webpack错误,npm run build失败

esbemjvw  于 2023-04-11  发布在  Webpack
关注(0)|答案(1)|浏览(427)

当我运行npm run build或尝试在Vercel上部署时,我的应用程序无法构建。执行npm run dev工作正常(现在我注解了整个processingQueue.js文件,但它之前也得到了相同的错误),但当我尝试在Vercel上部署时,得到以下输出:

[20:17:16.589] Running build in Cleveland, USA (East) – cle1
[20:17:16.640] Cloning github.com/SebastianRubina/affiliate-links (Branch: master, Commit: 630592c)
[20:17:16.646] Skipping build cache, deployment was triggered without cache.
[20:17:17.180] Cloning completed: 539.547ms
[20:17:17.288] Running "vercel build"
[20:17:17.724] Vercel CLI 28.18.3
[20:17:17.962] Installing dependencies...
[20:17:37.864] 
[20:17:37.864] added 457 packages in 20s
[20:17:37.864] 
[20:17:37.864] 123 packages are looking for funding
[20:17:37.864]   run `npm fund` for details
[20:17:37.886] Detected Next.js version: 13.2.4
[20:17:37.890] Detected `package-lock.json` generated by npm 7+...
[20:17:37.891] Running "npm run build"
[20:17:38.198] 
[20:17:38.198] > affiliate-links@0.1.0 build
[20:17:38.198] > next build
[20:17:38.198] 
[20:17:38.695] warn  - You have enabled experimental feature (appDir) in next.config.js.
[20:17:38.695] warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
[20:17:38.695] 
[20:17:38.696] info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
[20:17:38.712] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[20:17:38.713] This information is used to shape Next.js' roadmap and prioritize features.
[20:17:38.713] You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
[20:17:38.713] https://nextjs.org/telemetry
[20:17:38.713] 
[20:17:38.848] info  - Creating an optimized production build...
[20:17:41.503] 
[20:17:41.504] [1m[33mwarn[39m[22m - As of Tailwind CSS v3.3, the `@tailwindcss/line-clamp` plugin is now included by default.
[20:17:41.504] [1m[33mwarn[39m[22m - Remove it from the `plugins` array in your configuration to eliminate this warning.
[20:17:49.140] Failed to compile.
[20:17:49.140] 
[20:17:49.140] ./node_modules/chromium-bidi/lib/cjs/utils/processingQueue.js
[20:17:49.140] Module parse failed: Private field '#catch' must be declared in an enclosing class (30:13)
[20:17:49.141] File was processed with these loaders:
[20:17:49.141]  * ./node_modules/next/dist/build/webpack/loaders/next-flight-loader/index.js
[20:17:49.141]  * ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
[20:17:49.141] You may need an additional loader to handle the result of these loaders.
[20:17:49.142] |     #isProcessing = false;
[20:17:49.142] |     constructor(processor, _catch = ()=>Promise.resolve()){
[20:17:49.142] >         this.#catch = _catch;
[20:17:49.143] |         this.#processor = processor;
[20:17:49.143] |     }
[20:17:49.143] 
[20:17:49.143] Import trace for requested module:
[20:17:49.143] ./node_modules/chromium-bidi/lib/cjs/utils/processingQueue.js
[20:17:49.143] ./node_modules/chromium-bidi/lib/cjs/bidiMapper/BidiServer.js
[20:17:49.143] ./node_modules/chromium-bidi/lib/cjs/bidiMapper/bidiMapper.js
[20:17:49.143] ./node_modules/puppeteer-core/lib/esm/puppeteer/common/bidi/BidiOverCDP.js
[20:17:49.143] ./node_modules/puppeteer-core/lib/esm/puppeteer/common/bidi/bidi.js
[20:17:49.144] ./node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js
[20:17:49.144] ./node_modules/puppeteer-core/lib/esm/puppeteer/node/PuppeteerNode.js
[20:17:49.144] ./node_modules/puppeteer/lib/esm/puppeteer/puppeteer.js
[20:17:49.144] ./app/api/getItem/route.ts
[20:17:49.144] 
[20:17:49.144] 
[20:17:49.144] > Build failed because of webpack errors
[20:17:49.202] Error: Command "npm run build" exited with 1
[20:17:49.509] BUILD_UTILS_SPAWN_1: Command "npm run build" exited with 1

我试着进入文件和问题(processingQueue.js),试图找出什么是错误的,但无济于事。我评论了整个事情,使npm run dev的工作,但似乎没有修复它时,建设。
api/getItem/route.ts在日志中提到,下面是文件:

import { NextApiRequest, NextApiResponse } from "next";
import puppeteer from "puppeteer";

export async function POST(request: Request, response: NextApiResponse) {
  // const body = request.body;
  const req = await request.json();
  const url = req.amazonUrl;
  console.log("url", url);

  const browser = await puppeteer.launch({
    headless: true,
    defaultViewport: null,
  });
  const page = await browser.newPage();
  await page.goto(url, {
    waitUntil: "domcontentloaded",
  });

  const item = await page.evaluate(() => {
    const title = document.querySelector("#productTitle")?.innerHTML.trim();

    const imageContainer = document.querySelector(".imgTagWrapper");
    const imageUrl = imageContainer?.querySelector("img")?.src;
    const rating = document.querySelector(".a-icon-alt")?.textContent?.trim();
    let price = document
      .querySelector("#sns-base-price")
      ?.textContent?.trim()
      .slice(1)
      .replace(",", "");
    if (!price) {
      price = document
        .querySelector(".a-price-whole")
        ?.textContent?.trim()
        .replace(",", "");
    }
    return { title, price, imageUrl, rating };
  });

  return new Response(JSON.stringify(item));
}
qv7cva1a

qv7cva1a1#

我想你应该检查一下开发配置和生产配置之间的区别,我猜原因是swc-loader。你可以检查一下swc-loader的配置。顺便说一句,swc-loader的插件没有babel那么丰富,所以用babel代替可能会有用

相关问题