Webpack fails to load or resolve dependencies for npm packages imported via git

Recently, I started using gulp-starter and encountered an issue while including a private npm package called "Pigeon" from a GIT repository. Despite successfully installing the package with all its dependencies in the node_modules directory, I faced difficulties getting everything to work smoothly.

myApp/node_modules/pigeon/index.js:

export MyModule from './my-module.js';

myApp/src/app.js:

import ClientPigeoneer from 'pigeon';

Webpack loader:

  var webpackConfig = {
    context: 'myApp/src/scripts',
    plugins: [],
    resolve: {
      root: 'myApp/src/scripts',
      extensions: ['', '.js', '.json']
    },
    module: {
      loaders: [
        {
          test: /\.js$/,
          loader: 'babel-loader',
          exclude: /node_modules/,
          query: ["es2015", "stage-1"]
        }
      ]
    }
  }

Console output:

ERROR in ./~/pigeon/index.js
Module parse failed: /Users/mirague/Projects/myApp/node_modules/pigeon/index.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| export MyModule from './my-module';
|
 @ ./src/scripts/app.js 9:14-31

How can I resolve this issue with Webpack? Should I consider adding another loader?

Answer №1

Try implementing this revised code for resolving your issue:

resolve: {
    modulesDirectories: ['node_modules', 'myApp/src/scripts'],
    fallback: path.join(__dirname, 'node_modules'),
    extensions: ['', '.js', '.json']
},

By doing this, webpack will be able to search in your node modules directory for the installed modules.

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

Error occurs during npm installation, causing the node_modules directory to vanish unexpectedly

Excuse me if my query seems out of place; I have recently taken over a website that utilizes grunt, npm, and other tools to manage its styling and scripting assets. This is not my usual area of expertise (I am primarily a software developer filling in unti ...

The deserializeUser function in PassportJS is being ignored

My setup involves using Passport to authenticate users stored in mongodb. Everything seems to be working fine with authentication, including successful and failed login attempts as well as setting session variables. However, I am facing an issue where Pass ...

Determining whether a request should be processed by a middleware in an Express application dynamically

New Beginnings: As a newcomer to the world of Epxress, I recently built a middleware for checking user credentials. Here is how I specified it: var check = function(req, res, next){/* checking user cred*/} I then used it in my code like this: app.use(c ...

Transmitting information to the service array through relentless perseverance

I need assistance finding a solution to my question. Can my friends help me out? What types of requests do I receive: facebook, linkedin, reddit I want to simplify my code and avoid writing lengthy blocks. How can I create a check loop to send the same ...

"Unleashing the power of Discord.js: Crafting a dynamic command handler enhanced with collectors for smoother

I'm currently developing a Discord Bot that responds to specific commands. To simplify the process, I was considering implementing a system where the bot asks users for questions, collects their responses, and then provides the appropriate answers bas ...

GraphQL indicating a null value

Currently, I am delving deep into GraphQL and have defined two Object types. Let's see how they are structured: Firstly, The Book Type is outlined as follows: const BookType = new GraphQLObjectType({ name: 'Book', fields: () ...

Vuex was unable to locate the required dependency

Currently, I'm following an instructional video that incorporates Vuex. As shown in my package.json dependencies, I have installed Vuex: { "name": "blabla", "version": "1.0.0", "description": "blablaa", "author": "blabla", "private": true, ...

The inner joins in my SQL query are causing me to receive duplicate results

I am trying to retrieve the posts made by users followed by the userID (? in the query), as well as the posts by the user themselves. SELECT posts.id AS postid, posts.user AS user, posts.images AS images, posts.post_created, posts.textvalue, posts.te ...

A guide to handling react-router endpoints seamlessly on an express/node server

In my React frontend application, I am using react-router. The app is served from a directory called "/build" on my Express server. All back-end functionality (such as database operations) are handled by an endpoint at "localhost:3003/api/something", while ...

Is there a way to automatically redirect the server URL when a file is modified?

I am currently experimenting with a function that is supposed to only display a message in the console without redirecting the actual URL of my server when a file is changed. watcher.add("/home/diegonode/Desktop/ExpressCart-master/routes/2.mk"); watche ...

Guide to Making GraphQL API Calls from a Node.js/Express Server

After successfully implementing a schema and resolvers for my Express server, I tested them through /graphql. Now, I am looking to utilize the queries from a REST API by calling them in GET handlers like this: //[...] //schema and root are properly implem ...

Ways in which I can set up my route to work seamlessly with my controller in Node.js

I am developing an API using NodeJS and express Whenever I access a route, it works fine if the route is not connected to my controller. For example: router.get("/get", (req, res) => res.send({"data":"It works"})); However, when I integrate the contro ...

Having trouble locating the express module in your node application?

I am facing an issue that I can't seem to pinpoint the cause of, even though everything should be functioning properly. According to npm, I have express installed: C:\Users\phucker\Desktop>node init.js module.js:340 throw err; ...

What could be causing the slow loading time of my Shopify App developed using Next.js (React)?

I recently followed a tutorial at However, I am facing severe performance issues with my app. It loads extremely slowly when changing tabs, whether it's running on ngrok, localhost, or deployed on app engine. I'm new to React, Next.js, and Shop ...

The frisbyjs test is not passing due to the absence of proper HTTP headers being sent by the get()

My frisbyjs test is failing because the x-access-token and x-key HTTP headers are not being sent. Am I missing something? This seems like a simple mistake. Here is the outer test that contains the failing test within afterJSON(): frisby.create('Logi ...

What are the recommended TypeScript tsconfig configurations for running Node.js 10?

Can someone provide information on the necessary target/libs for enabling Node.js v10.x to utilize async/await without generators? I have found plenty of resources for node 8 but not as much for node 10. ...

Retrieving information from a JSON object that includes arrays

I've been researching how to extract data from the response body of a server, but I haven't had much luck finding a solution that works for my https request returning a JSON object. //Initiate the request: request({ //Specify the request met ...

Is there a way to identify Vue.js compilation errors proactively, before attempting to serve the application?

Spent hours troubleshooting why my Vue JS app was hanging when running npm run serve. Finally discovered it was due to a single error in one of my Vue files. The issue was hard to identify since it caused the console window to freeze. Are there better way ...

get a collection of chosen files in angular 7 and save them to

Greetings, I am currently working on a project and encountering an issue. I need to download multiple selected files from a list, but despite my efforts in searching for a solution, I have been unable to find one. While I can successfully download single f ...

Display an error message in Nodejs when the provided username or password is incorrect

I need assistance with handling errors in my post request redirect. app.route('/login') .get(function (req, res) { res.render('formUser', { title: 'Login User', action: 'login', error: 'empty or f ...