Error: The Next.js webpack module is missing in the npm local package

I'm currently developing a Next Js application that utilizes its mongoose models from a local npm package, allowing for shared functionality across different backend components. However, I am encountering the following errors:

Module not found: Can't resolve 'supports-color' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/debug/src'

../shared-stuff/node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy/package.json' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

../shared-stuff/node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'aws4' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

../shared-stuff/node_modules/mongodb/lib/encrypter.js
Module not found: Can't resolve 'mongodb-client-encryption' in '/Users/akopyl/Projects/my-project/shared-stuff/node_modules/mongodb/lib'

It appears that these errors are potentially caused by webpack attempting to search for dependencies of the shared-stuff package within the my-project/app directory instead of the designated my-project/shared-stuff directory.

The current file structure of the project is as follows:

my-project
├── app (Next Js application with errors)
│   ├── lib
│   ├── next.config.js
│   ├── node_modules
│   ├── package-lock.json
│   ├── package.json
│   ├── pages
│   ├── public
│   └── styles
├── gather
│   ├── ecosystem.config.js
│   ├── node_modules
│   ├── package-lock.json
│   ├── package.json
│   └── src
└── shared-stuff
    ├── index.js
    ├── models
    ├── node_modules
    ├── package-lock.json
    └── package.json

Contents of app/package.json:

{
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "mongoose": "^6.2.6",
    "next": "latest",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "sass": "^1.49.9",
    "shared-stuff": "file:../shared-stuff"
  },
  "devDependencies": {
    "eslint": "^8.11.0",
    "eslint-config-next": "^12.1.0"
  }
}

Contents of shared-stuff/package.json:

{
  "name": "shared-stuff",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "mongoose": "^6.2.6"
  }
}

One interesting observation is that although both packages only have mongoose as a dependency, the shared-stuff/node_modules folder contains a mongodb directory while the app/node_modules does not.

Another package located in the gather directory also lists shared-stuff as a dependency but operates without issues due to the absence of webpack usage.

I have attempted solutions such as running npm ci on all three projects, disabling eslint, and utilizing webpack.IgnorePlugin in next.config.js to ignore shared-stuff, unfortunately without success.

Answer №1

After some research, I managed to find a solution by setting up the main directory my-project as an npm project on its own and specifying the subdirectories as its workspaces.

my-project $ npm init -y
my-project $ npm install

Next, include the following line in the my-project/package.json file:

"workspaces": ["./app", "./gather", "./shared-stuff"]

By following these steps, the dependencies for the local folder package are successfully resolved.

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

Learning how to use Express.js to post and showcase comments in an HTML page with the help of Sqlite and Mustache templates

I am facing a persistent issue while trying to post new comments to the HTML in my forum app. Despite receiving various suggestions, I have been struggling to find a solution for quite some time now. Within the comments table, each comment includes attrib ...

How can I access the result of a getJSON promise within the $.when method?

I am working on a piece of code where I aim to collect data from 2 getjson calls and store it in an array only when both calls have successfully completed. However, I encountered the following error: resultFromUrl1.feed is undefined var entry1 = resultFro ...

Looking for a sophisticated approach in Spring MVC to manage the escaping and unescaping of strings being passed to the Front End

Currently, I am in the process of developing a web application utilizing Spring MVC. This project involves retrieving multiple objects from the Database, each containing strings as attributes. It's worth noting that I have no control over the format o ...

Material UI: Dynamic font scaling based on screen size

If I were to adjust the font size responsively in Tailwind, here's how it would look: <div className="text-xl sm:text-4xl">Hello World</div> When working with Material UI, Typography is used for setting text sizes responsively. ...

Assign a variable to a dynamic model within an AngularJS scope

I am facing an issue with scope closure. ... function(scope) { ... }); Within the scope, I need to achieve the following: $scope.favoriteTitle = 'some value' The challenge is that favoriteTitle cannot be static. It needs to be generated d ...

Scan the barcode with the reading device and then input it into

I'm exploring a method to transform a return function into a tab, or vice versa. My goal is to have the user scan a barcode, which would then move them to the next text field. Finally, when they reach the last field, the form should be submitted. I&ap ...

Transferring 'properties' to child components and selectively displaying them based on conditions

This is the code for my loginButton, which acts as a wrapper for the Button component in another file. 'use client'; import { useRouter } from 'next/navigation'; import { useTransition } from 'react'; interface LoginButtonPr ...

Having trouble accessing a component property in Angular 2

Hello, I am currently diving into Angular 2 and working on a project that involves basic CRUD functionality. I am encountering an issue with my User component where I am trying to access its property in the ngAfterViewInit hook, but it keeps showing as und ...

Generate a mesh representing an airplane, with vertices specifying various hues

After creating approximately 2500 meshes, I implemented an algorithm to determine the color of each mesh. The algorithm calculates a value based on the distance of each mesh to a "red-start" point, which then determines the final color. However, the curre ...

I'm having trouble getting the @microsoft/office-js library to import properly in my React JS project. Can anyone help me

I'm having trouble with a specific installation in my React web application. I've added '@microsoft/office-js' to my package.json file, and it's available in my node modules directory. But when I try to import it using import * as ...

I continue to encounter an error every time I attempt to place an HTML nested div on a separate line

When I structure the HTML like this, I don't encounter any errors: <div class="game-card"><div class="flipped"></div></div> However, if I format it differently, I receive an error message saying - Cannot set property 'vi ...

What is the best approach to link an HTML document to a MySQL Workbench server utilizing JavaScript, Ajax, and PHP?

On my HTML page, users can enter the name of a movie and if it is found in the database, the name will be displayed. I am attempting to establish a connection to the MySQL Workbench Server using JavaScript, Ajax, and PHP. This is what I have implemented s ...

Create a debounced and chunked asynchronous queue system that utilizes streams

As someone who is new to the concept of reactive programming, I find myself wondering if there exists a more elegant approach for creating a debounced chunked async queue. But what exactly is a debounced chunked async queue? While the name might need some ...

React function failing to utilize the latest state

I'm facing an issue with my handleKeyUp function where it doesn't seem to recognize the updated state value for playingTrackInd. Even though I update the state using setPlayingTrackInd, the function always reads playingTrackInd as -1. It's p ...

What is the reasoning behind Next.js adding an underscore prefix to app.js?

After using the command npx create-next-app> to generate a Next.js project, I noticed that there is an _app.js file in the pages folder. What situations require me to prefix a file with an underscore in a Next.js project? ...

ElementUI Cascader not rendering properly

Utilizing elementUI's cascading selector to present data, I have crafted this code in accordance with the official documentation. <el-cascader v-model="address" :options="addressOptions" :props="{expandTrigger: 'hover'}" ...

Display various MongoDB datasets in a single Express route

I currently have a get method in my Express app that renders data from a MongoDB collection called "Members" on the URL "/agileApp". This is working fine, but I now also want to render another collection called "Tasks" on the same URL. Is it possible to ...

Tips for organizing multiple TextField components within a Grid container using Material-UI

I utilize Material-UI for my front-end design needs. I have a query related to the Grid layout feature. My goal is to include 7 TextField elements, but they are appearing overlapped. When I modify all 7 TextField elements from xs={1} to xs={2}, they become ...

What are some ways to implement smooth scrolling when a navigation link is clicked?

I have a total of 3 links in my navigation bar and every time they are clicked, I want the page to smoothly scroll down to their designated section on the webpage. Although I have already set up the anchors, I lack experience in scripting to create the smo ...

I am facing an issue with connecting Prisma to my Next.js middleware. What steps can I take to resolve this connectivity problem?

My goal is to restrict access to my Next.js website to authenticated users only. However, I encountered the following error: Error [PrismaClientValidationError]: PrismaClient failed to initialize because it wasn't configured to run in this environment ...