Yarn Plug'n'Play was unable to locate the module during the next build

Currently, I am in the process of developing a Next.js project with yarn's Plug'n'Play feature. In this project, I have created several pages and added various packages, including mathjs: '^10.3.0' to assist me in parsing user input. TypeScript and eslint are being used simultaneously.

While everything runs smoothly when executing yarn dev, encountering an issue arises when attempting to compile the project using yarn build. The specific error received is as follows:

# yarn build
info  - Checking validity of types
info  - Creating an optimized production build
info  - Compiled successfully

> Build error occurred
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'mathjs' imported from E:\Code\JavaScript\Web\next\yolcruz\.next\server\pages\calculator.js
Did you mean to import mathjs-npm-10.3.0-2f674e19b3-3fb3b66be9.zip/node_modules/mathjs/lib/cjs/index.js?
    at new NodeError (node:internal/errors:371:5)
    at packageResolve (node:internal/modules/esm/resolve:930:9)
    at moduleResolve (node:internal/modules/esm/resolve:976:18)
    at defaultResolve (node:internal/modules/esm/resolve:1078:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
    at ESMLoader.import (node:internal/modules/esm/loader:332:22)
    at importModuleDynamically (node:internal/modules/cjs/loader:1042:29)
    at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
    at importModuleDynamically (node:vm:381:46) {
  type: 'Error',
  code: 'ERR_MODULE_NOT_FOUND'
}
info  - Collecting page data .

My approach involves leveraging yarn's Plug'n'Play functionality, which means there is no node_modules directory present, and other packages do not cause errors during development. Could someone provide guidance on resolving this issue? Is it attributable to the package itself or a consequence of using Plug'n'Play?

The contents of my package.json file are as shown below:

{
  "name": "yolcruz",
  "packageManager": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6bfa7b4a886f5e8f7e8f7">[email protected]</a>",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@typescript-eslint/eslint-plugin": "latest",
    "@typescript-eslint/parser": "latest",
    "eslint-plugin-react": "latest",
    "mathjs": "^10.3.0",
    "next": "^12.1.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-icons": "^4.3.1",
  },
  "devDependencies": {
    "@types/eslint": "^8",
    "@types/node": "^17.0.18",
    "@types/react": "^17",
    "@types/react-dom": "^17",
    "autoprefixer": "^10.4.2",
    "eslint": "^8.9.0",
    "eslint-config-next": "^12.1.0",
    "typescript": "^4.5.5"
  }
}

Additionally, the node version being utilized is 16.14.0

Answer №1

After some troubleshooting, I managed to find a solution. By updating to the latest version of yarn using the command yarn set version latest, I was able to upgrade to v3.2.0. Following this, I executed yarn rebuild to address and update or remove any problematic dependencies causing errors. The issue has now been resolved, and everything is functioning properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing the useState hook with generics in React for efficient data management

Utilizing a unique react hook designed to manage input validation for text fields and checkboxes, adaptable to both string and boolean values through the use of generics. An error is encountered when attempting to assign a value using setValue, displaying ...

Encountering an issue while setting up a Next.js project, I am struggling to find a solution despite trying various methods

I attempted to install Next.js, and even updated my npm version in order to create a new React project with the latest Next.js. However, I kept encountering the same error. Aborting installation. Unexpected error. Please report it as a bug: Error: spawn ...

The perpetual loop in React context triggered by a setState function within a useEffect block

I'm experiencing an endless loop issue with this context component once I uncomment a specific line. Even after completely isolating the component, the problem persists. This peculiar behavior only manifests when the row is discounted and the browser ...

Error encountered with ts-loader in the node_modules/@types directory within Webpack

After successfully compiling my project, I encountered errors when trying to run npm install and then webpack in a new directory. The errors are as follows: ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts (500,12): error TS10 ...

What is the best way to create a function that shifts a musical note up or down by one semitone?

Currently developing a guitar tuning tool and facing some hurdles. Striving to create a function that can take a musical note, an octave, and a direction (up or down), then produce a transposed note by a half step based on the traditional piano layout (i. ...

Is it possible to transfer data between pages by utilizing state in the Next.js 13 App directory?

Can Nextjs 13 App Router be used to efficiently pass previewData from MainComponent.jsx to Preview.jsx as a State, without involving query parameters or props? I want to transfer the data as state from MainComponent.jsx, then navigate to the Result.jsx com ...

The Vue router fails to load when using create-vue@3

I've been experimenting with the Vue Router, but it's not giving me the expected outcome. While following the tutorial on https://router.vuejs.org/guide/, I found that if I use the CDN and place it in a standalone HTML file, it works fine. Howev ...

How to Access localStorage using NextJs getInitialProps

I have been working with localStorage token in my next.js application. I encountered an issue when trying to retrieve the localStorage on page getInitialProps as it always returns undefined. For example, Dashboard.getInitialProps = async () => { con ...

The various types of Angular 2 FormBuilders

As I delved into learning Angular 2, I initially came across ngModel, and later discovered FormGroup/FormBuilder which seemed more suitable for handling complex forms. However, one downside that caught my attention was that by using FormBuilder, we sacrifi ...

What is the best way to retrieve nested reference data all at once from a Firestore document?

I have two distinct collections stored within my Firestore database. The first collection is users, and it can be visualized as shown here: https://i.stack.imgur.com/AKlyM.png The second collection is posts, represented by the following structure: http ...

I'm having trouble getting plugins to work in React Markdown with Next.js

In my current project, I am using next.js on the frontend and strapi on the backend. To render the rich text from strapi that includes markdown, I have implemented ReactMarkdown package version "6.0.3" in the frontend. Everything works smoothly except for ...

Checking a sequence using a list of strings

I have an array containing a list of IDs: var listId: string[] = []; var newId: boolean; for (let i in data.chunk) { listId.push(data.chunk[i].aliases[0]); } My objective is to compare a new ID with the entire list. If the new ID is found in the list ...

Make dark mode the default setting in your Next JS application

In my Next JS application, I have implemented both isDarkMode and handleDarkMode functions. Within the Header component, there is a toggle button that allows users to switch between light and dark modes. <ThemeContainer> <label classN ...

Varied Data Transfer Objects used for requests and responses

Currently, I am dealing with MongoDB and subdocuments. MongoDB automatically adds extra fields that cannot be specified in a POST request; they can only be retrieved using a GET request. To put it simply: different data transfer objects (dtos). I am utili ...

Establishing the data type for the state coming from the API

Whenever I try to add a new API response to the status, it shows as undefined. I need to filter out the incoming data from randomcocktail and then put it to use. Random.tsx import { useState, useEffect } from "react"; import { CocktailType } ...

There seems to be a malfunction with the routing feature in the src/index.html file

My routing setup is not functioning as expected in src/index.html angular. What I have is a header with some links for navigation: <header> <div class="logo"> <div class="logo-img-div"> <img src="../../ass ...

Managing numerous subscriptions to private subjects that are revealed by utilizing the asObservable() method

I'm using a familiar approach where an Angular service has a private Subject that provides a public Observable like this: private exampleSubject = new Subject<number>(); example$ = this.exampleSubject.asObservable(); In my particular situation, ...

TypeScript is unaware that a component receives a necessary prop from a Higher Order Component (HOC)

My component export is wrapped with a higher-order component (HOC) that adds a required prop to it, but TypeScript seems unaware that this prop has already been added by the HOC. Here's the Component: import * as React from "react"; import { withTex ...

Bypassing the email verification step during the registration process in Supabase using auth-helpers for Next.js and the 'pages' folder

Initially, I set up client-side authentication in my NextJS application using the supabase-js library. However, I am now transitioning to using the auth-helpers-nextjs library for authentication so that I can access the User server-side (specifically for s ...

Incorporating quotes into a unified npm script

I'm trying to merge two npm scripts into one, but the result is incorrect and causes issues with passing flags. I can't use the dotenv package, and using ampersands isn't solving the problem. Here's what I have in my package.json file ...