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.

ModuleNotFoundError: Module not found: Error: Can't resolve 'pnpapi'

See original GitHub issue

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

"@sentry/nextjs": "6.4.1",

Description

When we include import * as Sentry from '@sentry/nextjs' anywhere within the app - it throws this ModuleNotFoundError: Module not found: Error: Can't resolve 'pnpapi' this error on build yarn run build - FWIW - we are still on webpack4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ani4aniketcommented, Aug 27, 2021

@AbhiPrasad, Thanks for the solution, changing the target to experimental-serverless-trace works but if the project is deployed on Netlify failed while running netlify build. Hoping to get some solution.

2reactions
AbhiPrasadcommented, May 26, 2021

Hey @followbl, thanks for the detailed config. It seems the issue is related to the target: serverless in your webpack config. It seems that Vercel folks prefer the experimental-serverless-trace target over theserverless target. Vercel Now also uses experimental-serverless-trace now from what I see.

See the PR adding experimental-serverless-trace to the nextjs repo for more details around this.

Could you try replacing the serverless target with experimental-serverless-trace and seeing if the build errors still occur? This fixes it on our end.

diff --git a/next.config.js b/next.config.js
index 98944a6..72dfa74 100644
--- a/next.config.js
+++ b/next.config.js
@@ -101,7 +101,7 @@ const nextJsConfig = {
       ];
     },
   },
-  target: 'serverless',
+  target: 'experimental-serverless-trace',
   webpack: (config, options) => {
     if (!options.dev && options.isServer) {
       // we're in build mode so enable shared caching for the GitHub API

If the serverless target is required for your setup, please let us know and we can continue investigating, but the experimental-serverless-trace target should cover all the use cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module not found: Error: Can't resolve 'pnpapi' in '/app ...
Encountered this bug error when when I tried to build my next app. Build error occurred. Error: > Build failed because of webpack...
Read more >
reactjs - module not found: Error: Can't resolve 'pnpapi' in '/app ...
This import appeared in my code, in the index of my application. I removed it and webpack was working again.
Read more >
Can't resolve 'pnpapi' with webpack 5.4.0 - Rysolv
I'm still getting this error, but with yarn berry. Cannot find module 'pnpapi' from 'rootDir/.yarn/cache/enhanced-resolve-npm-5.9.2- ...
Read more >
Next.js + Webpack - Fix for ModuleNotFoundError: Module not ...
To fix the error with Webpack 5, update your Next.js config file ( /next.config.js ) with the following, it tells webpack not to...
Read more >
module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
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