question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Broken on Next.js 10.2.0 which uses Webpack 5 when running a custom server to support HTTPS locally

See original GitHub issue

Bug description

When I upgrade Next.js to 10.2.0 which uses Webpack 5 and then run node server.js to run my app locally using HTTPS, I get this error:

error - ./prisma/client/runtime/index.js:24474:15
Module not found: Can't resolve '_http_common'
  24472 | var require_http_parser = __commonJS2((exports2, module2) => {
  24473 |   "use strict";
> 24474 |   var common = require("_http_common");
        |               ^
  24475 |   if (common.HTTPParser) {
  24476 |     module2.exports = common.HTTPParser;
  24477 |   } else {

How to reproduce

Typically you run Next.js apps locally by running npm run dev and thatā€™s it, but if you want to use HTTPS locally then you have to do something a bit different which involves creating a file usually called ā€œserver.jsā€ which attaches the SSL certificate and then runs the server. I have no idea if this particularly issue is related to that or if it would happen without HTTPS, as I only use this method now. Iā€™m hoping the error message alone might make the issue apparent to anyone who understands what itā€™s saying, and why Webpack 5 would cause this.

Expected behavior

Everything works just as it would on Next.js <10.2.0 / Webpack 4.

Environment & setup

  • OS: macOS Big Sur
  • Database: MySQL / Amazon Aurora
  • Node.js version: 14.16.0
  • Prisma version:
prisma               : 2.22.0
@prisma/client       : 2.22.0
Current platform     : darwin
Query Engine         : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio               : 0.379.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:26 (12 by maintainers)

github_iconTop GitHub Comments

6reactions
belgattitudecommented, Aug 25, 2021

@gavrichards If it helps I upgraded to nextjs 11.1.0 / webpack 5, prisma 2.30.0 and this next.config.js trick still works with node 14.x:

  webpack: (config, { defaultLoaders, isServer }) => {
    // thx  https://github.com/prisma/prisma/issues/6899#issuecomment-849126557
    if (isServer) {
      config.externals.push('_http_common');
    }
    return config;
  },

PS: a full config is here https://github.com/belgattitude/nextjs-monorepo-example/blob/main/apps/web-app/next.config.js#L127

4reactions
finnatseacommented, Sep 29, 2021

For what itā€™s worth, I simply needed to remove target: "serverless" from next.config.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 Adoption - Next.js
Using webpack 5 in your application has many benefits, notably: Improved Disk Caching: next build is significantly faster on subsequent builds; Improved FastĀ ......
Read more >
How to use webpack 5 configs in Next.js? - Stack Overflow
Webpack 5 is now the default for all Next.js applications. If you did not have custom webpack configuration your application is already using...
Read more >
How to Add Push Notifications to a Next.js App - OneSignal
In this guide, I'll show you how to integrate with OneSignal in order to add web push notifications to a React app built...
Read more >
Migration Guide | Cypress Documentation
The minimum Node.js version supported to install Cypress is Node.js 14+. ... Use the cy.session() command to preserve cookies (and local andĀ ...
Read more >
All side optimized Next.js translations (a next-i18next guide)
Optimize your Next.js app to best work with translations on server side and on client side with next-i18next.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found