martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Missing issuer in Webpack Rule breaks build #299

Open droegier opened 10 months ago

droegier commented 10 months ago

Are you trying to transpile a local package or an npm package? Unclear. Could be both.

Describe the bug When I run next build it fails.

> Build error occurred
TypeError: Cannot read properties of undefined (reading 'and')
    at Object.webpack (/Users/davidroegiers/Jurata/jurata-web/web/node_modules/next-transpile-modules/src/next-transpile-modules.js:201:60)
    at getBaseWebpackConfig (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/build/webpack-config.js:2163:32)
    at async Promise.all (index 0)
    at async Span.traceAsyncFn (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/trace/trace.js:103:20)
    at async webpackBuildImpl (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/build/webpack-build/impl.js:133:21)
    at async webpackBuild (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/build/webpack-build/index.js:137:16)
    at async /Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/build/index.js:595:123
    at async Span.traceAsyncFn (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/trace/trace.js:103:20)
    at async build (/Users/davidroegiers/.nvm/versions/node/v18.9.0/lib/node_modules/next/dist/build/index.js:148:29)

To Reproduce run next build for my Jurata project on my local machine

Expected behavior I expect it to run without failing.

Setup

const path = require('path');
const withTM = require('next-transpile-modules')([
  'jurata-styleguide',
  'strict-uri-encode',
  'split-on-first',
  'query-string',
]);
const { i18n, rewrites, oldHomepagePathsRedirects } = require('./next-i18next.config');

const config = withTM(
  {
    async rewrites() {
      return rewrites;
    },
    webpack(config, options) {
      // Support SVG import
      config.module.rules.push({
        test: /\.(svg)$/,
        use: ['raw-loader'],
      });

      // Prevent duplicate modules from the styleguide package, a better
      // solution is welcome
      config.resolve.alias['react'] = path.resolve('./node_modules/react');
      config.resolve.alias['react-dom'] = path.resolve('./node_modules/react-dom');
      config.resolve.alias['@emotion/core'] = path.resolve('./node_modules/@emotion/core');
      config.resolve.alias['@emotion/react'] = path.resolve('./node_modules/@emotion/react');

      if (!options.isServer) {
        config.resolve.alias['contentful'] = path.resolve('./node_modules/contentful/dist/contentful.legacy.min.js');
      }

      // This is needed
      config.resolve.alias['joi'] = path.resolve('./node_modules/joi/lib/index.js');

      return config;
    },
  },
  { debug: true }
);

module.exports = {
  i18n,
  ...config,
  async redirects() {
    const isProduction = process.env.NEXT_PUBLIC_ENVIRONMENT === 'production';
    const redirects = [
      {
        source: '/rechtsguide/wp-content/uploads/2021/05/Jurata-Virtual-Lawyer.svg',
        destination: 'https://s3.eu-central-1.amazonaws.com/jurata.ch/Jurata-Virtual-Lawyer.svg',
        permanent: false,
      },
      {
        source: `/rechtsguide/:path*`,
        destination: `/de`,
        permanent: false,
      },
      {
        source: `/zkb`,
        destination: `/de/unternehmen-gruenden-zkb`,
        permanent: false,
      },
      {
        source: '/trademark',
        destination: '/de/markenschutz',
        permanent: false,
      },
      {
        source: '/start-summit',
        destination: '/en',
        permanent: false,
      },
      {
        source: '/startup-nights-2022',
        destination: '/',
        permanent: false,
      },
      {
        source: '/gruenden',
        destination: '/de/unternehmen-gruenden',
        permanent: false,
      },
      ...oldHomepagePathsRedirects,
      process.env.NEXT_PUBLIC_MAINTENANCE === 'true'
        ? {
            source: '/((?!maintenance).*)*',
            destination: '/maintenance.html',
            permanent: false,
          }
        : null,
    ].filter(Boolean);

    return isProduction
      ? [
          {
            source: '/:path*',
            has: [
              {
                type: 'query',
                key: 'i',
                value: '(?!.*_admin)(.*(?:incorporation|Incorporation)).*',
              },
            ],
            destination: 'https://www.jurata.ch/de/unternehmen-gruenden',
            permanent: false,
          },
          {
            source: '/:path*',
            has: [
              {
                type: 'query',
                key: 'i',
                value: '(?!.*_admin)(.*(?:trademark|Trademark)).*',
              },
            ],
            destination: 'https://www.jurata.ch/de/markenschutz',
            permanent: false,
          },
          ...redirects,
        ]
      : redirects;
  },
  images: {
    domains: [
      process.env.NEXT_PUBLIC_COCKPIT_URL_PUBLIC.replace('https://', ''),
      'images.ctfassets.net',
      'backend.staging.jurata.ch',
      'backend.jurata.ch',
      'cockpit.staging.jurata.ch',
      'cockpit.jurata.ch',
    ],
    formats: ['image/avif', 'image/webp'],
  },
};