javascript 迁移到Next 13后的Webpack错误

y4ekin9u  于 2023-04-10  发布在  Java
关注(0)|答案(1)|浏览(159)

升级到版本13之后,我们的应用程序无法构建,看起来webpack在导入和导出以及可能的typescript方面存在问题

../../libs/queries/src/lib/groq/searchFaq.ts
Module parse failed: Unexpected token (1:37)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export const searchFaqQuery = (market: string, language: string, searchTerm: string) => {
|   const searchTermArray = searchTerm.split(' ').map((word) => word + '*');
|   const queryFilters = `market == '${market}' && language == '${language}' && _type == 'faq' && !(_id in path("drafts.**"))`;

Import trace for requested module:
../../libs/queries/src/lib/groq/searchFaq.ts
../../libs/queries/src/index.ts

../../libs/utils/src/lib/components/atoms/BulletListWrapper/BulletListWrapper.tsx
Module parse failed: Unexpected token (4:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import * as Styled from './BulletListWrapper.style';
| 
> type TBulletListWrapper = {
|   children: React.ReactNode;
| };

Import trace for requested module:
../../libs/utils/src/lib/components/atoms/BulletListWrapper/BulletListWrapper.tsx
../../libs/utils/src/lib/components/atoms/index.ts
../../libs/utils/src/lib/components/index.ts
../../libs/utils/src/index.ts

错误列表更长,但与上面的非常相似。我的next.config.js看起来是这样的:

module.exports = {
  env: {
    NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_SANITY_TOKEN,
    NEXT_PUBLIC_PREVIEW_SECRET: process.env.NEXT_PUBLIC_SANITY_PREVIEW_SECRET,
    NEXT_PUBLIC_PROJECT_ID: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
  },
  i18n: {
    defaultLocale: 'et',
    locales: ['et', 'ru'],
  },
  basePath: '/ee',
  reactStrictMode: true,
  images: {
    domains: ['cdn.images.io'],
    formats: ['image/webp'],
  },
  experimental: {
    forceSwcTransforms: true,
  },
  swcMinify: true,
  webpack(config) {
    config.resolve.fallback = { fs: false, path: false };
    config.module.rules.push({
      test: /\.svg$/,
      issuer: {
        and: [/\.(js|ts)x?$/],
      },
      use: ['@svgr/webpack'],
    });

    return config;
  },
};

请你指出我在正确的方向?我们有一个monorepo与NX和我升级后,一切工作没有问题的发展,但当谈到构建应用程序似乎有一个问题.谢谢.

b0zn9rqh

b0zn9rqh1#

听起来像是nx使用过时的nextjs内部组件的问题。根本原因在www.example.com中描述https://github.com/vercel/next.js/issues/46374#issuecomment-1446065787,并在nx@15.8.7中修复。

相关问题