Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from 10.0.0 to 10.0.5 failed with "webpack config.resolve.alias was incorrectly overridden" #20950

Closed
Vadorequest opened this issue Jan 10, 2021 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@Vadorequest
Copy link
Contributor

Vadorequest commented Jan 10, 2021

What version of Next.js are you using?

10.0.5

What version of Node.js are you using?

12

What browser are you using?

Chrome

What operating system are you using?

MacOS

How are you deploying your application?

Vercel

Describe the Bug

20:41:30.594 Module parse failed: Unexpected token (52:30)
20:41:30.594 File was processed with these loaders:
20:41:30.594 * ./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js
20:41:30.594 You may need an additional loader to handle the result of these loaders.
20:41:30.594 | canonicalBase: "",
20:41:30.594 | generateEtags: true,
20:41:30.594 > poweredByHeader: Next Right Now - With love - https://github.com/UnlyEd/next-right-now,
20:41:30.594 |
20:41:30.594 | runtimeConfig,
20:41:30.594 > Build error occurred
20:41:30.595 Error: > webpack config.resolve.alias was incorrectly overridden. https://err.sh/vercel/next.js/invalid-resolve-alias
20:41:30.595 at /vercel/workpath0/node_modules/next/dist/build/index.js:15:787
20:41:30.595 at async /vercel/workpath0/node_modules/next/dist/build/tracer.js:1:525
20:41:30.659 error Command failed with exit code 1.

Expected Behavior

Should build, was building fine before migrating to Next.js v10.0.5, from v10.0.0

To Reproduce

Deploy UnlyEd/next-right-now#243 on Vercel

Vercel deploy logs:

20:40:13.007  	Running "yarn run build"
20:40:13.347  	yarn run v1.22.4
20:40:13.381  	$ yarn test:once:group:no-integration && next build
20:40:13.768  	$ NODE_ENV=test jest --group=-integration
20:40:29.130  	PASS src/utils/data/record.test.ts (13.748 s)
20:40:30.200  	PASS src/components/assets/GraphCMSAsset.test.tsx (14.84 s)
20:40:31.244  	PASS src/utils/caching/hybridCache.test.ts (15.915 s)
20:40:31.418  	PASS src/utils/js/url.test.ts
20:40:32.314  	PASS src/utils/js/string.test.ts
20:40:32.373  	PASS src/utils/js/array.test.ts
20:40:32.593  	PASS src/utils/cookies/UniversalCookiesManager.browser.test.ts
20:40:33.185  	PASS src/utils/assets/logo.test.ts
20:40:33.312  	PASS src/utils/css.test.ts
20:40:33.466  	PASS src/utils/gql/graphcms.test.ts
20:40:34.241  	PASS src/utils/api/fetchJSON.test.ts
20:40:34.289  	PASS src/utils/cookies/UniversalCookiesManager.server.test.ts
20:40:34.343  	Test Suites: 1 skipped, 12 passed, 12 of 14 total
20:40:34.343  	Tests:       9 skipped, 68 passed, 77 total
20:40:34.343  	Snapshots:   16 passed, 16 total
20:40:34.343  	Time:        19.408 s
20:40:34.343  	Ran all test suites.
20:40:35.257  	Loaded env from /vercel/workpath0/.env
20:40:35.261  	Building Next with NODE_ENV="production" NEXT_PUBLIC_APP_STAGE="staging" for NEXT_PUBLIC_CUSTOMER_REF="customer1" using GIT_COMMIT_SHA=1d0d94e24c32e1dc5d481d9e880d311b54cc1546 and GIT_COMMIT_REF=refs/heads/gcms-update-packages-2021-01
20:40:35.261  	Deployment will be tagged automatically, using GIT_COMMIT_TAGS: "v4.0.x-rc-gcms-update-packages-2021-01"
20:40:35.261  	Release version resolved from tags: "v4.0.x-rc-gcms-update-packages-2021-01" (matching first tag starting with "v")
20:40:35.263  	Using headers: [
20:40:35.263  	  {
20:40:35.263  	    "source": "/(.*?)",
20:40:35.263  	    "headers": [
20:40:35.263  	      {
20:40:35.263  	        "key": "Content-Security-Policy",
20:40:35.263  	        "value": "frame-ancestors *.stacker.app"
20:40:35.263  	      }
20:40:35.263  	    ]
20:40:35.263  	  }
20:40:35.264  	]
20:40:35.265  	Using rewrites: [
20:40:35.265  	  { source: '/', destination: '/api/autoRedirectToLocalisedPage' },
20:40:35.265  	  {
20:40:35.265  	    source: '/:locale((?!fr|en-US|en|robots|static|favicon.ico|_next|api)[^/]+)(.*)',
20:40:35.265  	    destination: '/api/autoRedirectToLocalisedPage'
20:40:35.266  	  },
20:40:35.266  	  { source: '/robots.txt', destination: '/robots/!production.txt' }
20:40:35.266  	]
20:40:35.266  	Using redirects: [
20:40:35.266  	  { source: '/:locale/', destination: '/:locale', permanent: true },
20:40:35.266  	  {
20:40:35.266  	    source: '/:locale/:path*/',
20:40:35.266  	    destination: '/:locale/:path*',
20:40:35.266  	    permanent: true
20:40:35.266  	  }
20:40:35.267  	]
20:40:35.269  	info  - Creating an optimized production build...
20:40:35.303  	Attention: Next.js now collects completely anonymous telemetry regarding usage.
20:40:35.303  	This information is used to shape Next.js' roadmap and prioritize features.
20:40:35.303  	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:40:35.303  	https://nextjs.org/telemetry
20:40:46.623  	[webpack] Building release "v4.0.x-rc-gcms-update-packages-2021-01" using NODE_ENV="production" with IS_SERVER_INITIAL_BUILD="1"
20:40:47.092  	info  - Using external babel configuration from /vercel/workpath0/babel.config.js
20:41:30.593  	Failed to compile.
20:41:30.593  	./node_modules/next/dist/build/webpack/loaders/next-serverless-loader?page=%2F404&absolutePagePath=private-next-pages%2F404.tsx&absoluteAppPath=private-next-pages%2F_app.tsx&absoluteDocumentPath=private-next-pages%2F_document.tsx&absoluteErrorPath=private-next-pages%2F_error.tsx&absolute404Path=private-next-pages%2F404.tsx&distDir=private-dot-next&buildId=4dgXMttIYvbAESS3dKlTa&assetPrefix=&generateEtags=true&poweredByHeader=Next%20Right%20Now%20-%20With%20love%20-%20https%3A%2F%2Fgithub.com%2FUnlyEd%2Fnext-right-now&canonicalBase=&basePath=&runtimeConfig=&previewProps=%7B%22previewModeId%22%3A%228b5831430a2096c806dc4a0463a36854%22%2C%22previewModeSigningKey%22%3A%22a7513015915686b2bfc8dd430c795ca56e96a4efd9b29357b30dfd1006a5ce48%22%2C%22previewModeEncryptionKey%22%3A%22eaba394554ec6ae798f339ce40116136dc0a86428d9d729a137db324f232cfb8%22%7D&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oYXQgeW91IGNhbiBydW4gdGhlIGRlbW8gbG9jYWxseSB3aXRob3V0IGhhdmluZyB0byBj
20:41:30.594  	Module parse failed: Unexpected token (52:30)
20:41:30.594  	File was processed with these loaders:
20:41:30.594  	 * ./node_modules/next/dist/build/webpack/loaders/next-serverless-loader/index.js
20:41:30.594  	You may need an additional loader to handle the result of these loaders.
20:41:30.594  	|         canonicalBase: "",
20:41:30.594  	|         generateEtags: true,
20:41:30.594  	>         poweredByHeader: Next Right Now - With love - https://github.com/UnlyEd/next-right-now,
20:41:30.594  	|   
20:41:30.594  	|         runtimeConfig,
20:41:30.594  	> Build error occurred
20:41:30.595  	Error: > webpack config.resolve.alias was incorrectly overridden. https://err.sh/vercel/next.js/invalid-resolve-alias
20:41:30.595  	    at /vercel/workpath0/node_modules/next/dist/build/index.js:15:787
20:41:30.595  	    at async /vercel/workpath0/node_modules/next/dist/build/tracer.js:1:525
20:41:30.659  	error Command failed with exit code 1.
20:41:30.659  	info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
20:41:30.672  	Error: Command "yarn run build" exited with 1
20:41:35.585  	Done with "package.json"

Here is the content of my next.config.js file:

  ...

  /**
   *
   * The webpack function is executed twice, once for the server and once for the client.
   * This allows you to distinguish between client and server configuration using the isServer property.
   *
   * @param config Current webpack config. Useful to reuse parts of what's already configured while overridding other parts.
   * @param buildId The build id, used as a unique identifier between builds.
   * @param dev Indicates if the compilation will be done in development.
   * @param isServer It's true for server-side compilation, and false for client-side compilation.
   * @param defaultLoaders Default loaders used internally by Next.js:
   *  - babel Default babel-loader configuration
   * @see https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
   */
  webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
    ...

    // XXX See https://github.com/vercel/next.js/blob/canary/examples/with-sentry-simple/next.config.js
    // In `pages/_app.js`, Sentry is imported from @sentry/node. While
    // @sentry/browser will run in a Node.js environment, @sentry/node will use
    // Node.js-only APIs to catch even more unhandled exceptions.
    //
    // This works well when Next.js is SSRing your page on a server with
    // Node.js, but it is not what we want when your client-side bundle is being
    // executed by a browser.
    //
    // Luckily, Next.js will call this webpack function twice, once for the
    // server and once for the client. Read more:
    // https://nextjs.org/docs#customizing-webpack-config
    //
    // So ask Webpack to replace @sentry/node imports with @sentry/browser when
    // building the browser's bundle
    if (!isServer) {
      config.resolve.alias['@sentry/node'] = '@sentry/browser';
    }

    return config;
  },

  /**
   * Next.js exposes some options that give you some control over how the server will dispose or keep in memory built pages in development.
   *
   * XXX We documented this function in case you might want to use it, but we aren't using it.
   *
   * @see https://nextjs.org/docs/api-reference/next.config.js/configuring-onDemandEntries
   */
  // onDemandEntries: {
  //   // period (in ms) where the server will keep pages in the buffer
  //   maxInactiveAge: 25 * 1000,
  //   // number of pages that should be kept simultaneously without being disposed
  //   pagesBufferLength: 2,
  // },

  poweredByHeader: 'Next Right Now - With love - https://github.com/UnlyEd/next-right-now', // See https://nextjs.org/docs/api-reference/next.config.js/disabling-x-powered-by
}));

It seems the issue might be related to config.resolve.alias['@sentry/node'] = '@sentry/browser'; (from the error message). This used to work fine since Next.js v9. Did something change?

I don't know if that's related to Vercel or Next. Most likely Next.js itself.

Also, there seems to be an issue with the poweredByHeader, once again, this used to work fine.

@Vadorequest Vadorequest added the bug Issue was opened via the bug report template. label Jan 10, 2021
@Vadorequest Vadorequest changed the title webpack config.resolve.alias was incorrectly overridden Upgrade from 10.0.0 to 10.0.5 failed with "webpack config.resolve.alias was incorrectly overridden" Jan 10, 2021
@Vadorequest
Copy link
Contributor Author

Digging deeper and focusing on the issue at hand, I could figure out this is the behaviour since Next.js v10.0.4. See UnlyEd/next-right-now#243

I ran the same code under 5 version (10.0.0 ... 10.0.5) of Next, and the 10.0.4 and 10.0.5 failed with the same error output.

@timneutkens
Copy link
Member

The issue here is that you're using incorrect configuration values, only true and false are supported by poweredByHeader

@Vadorequest
Copy link
Contributor Author

@timneutkens I think it's only part of the overall problem.

It seems the issue might be related to config.resolve.alias['@sentry/node'] = '@sentry/browser'; (from the error message). This used to work fine since Next.js v9. Did something change?

20:41:30.594  	> Build error occurred
20:41:30.595  	Error: > webpack config.resolve.alias was incorrectly overridden. https://err.sh/vercel/next.js/invalid-resolve-alias
20:41:30.595  	    at /vercel/workpath0/node_modules/next/dist/build/index.js:15:787
20:41:30.595  	    at async /vercel/workpath0/node_modules/next/dist/build/tracer.js:1:525
20:41:30.659  	error Command failed with exit code 1.

I'll change the poweredByHeader, but the other error doesn't seem related to poweredByHeader.

Vadorequest added a commit to UnlyEd/next-right-now that referenced this issue Jan 17, 2021
@Vadorequest
Copy link
Contributor Author

Vadorequest commented Jan 17, 2021

You were right, the poweredByHeader fixed it, it wasn't related to sentry (despite the logs saying so)

PR: UnlyEd/next-right-now#261

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants