dimanche 18 août 2019

How to point webpack to a specific node_modules folder

I am trying to build a grpc web client and I need to pack the code to resolve the require statements.

I have compiled the protos to js and it works if I have them in the current folder where I have installed the node modules.

The problem is if I have the compiled proto in some other place and I require them from there, webpack looks for the node modules in that path.

From my client.js

working version:

const {StopRequest, StopReply} = require('./work_pb.js');

Problematic version:

const {StopRequest, StopReply} = require('../../../messages/proto/output/work_pb.js');

In this last case it looks for the node modules in ../../../messages/proto/output/. The node modules are installed in the current path where my client.js is and from where I ran npx webpack client.js.

ERROR in /home/xxx/yyy/zzz/messages/proto/output/transmission_pb.js
Module not found: Error: Can't resolve 'google-protobuf' in '/home/xxx/yyy/zzz/messages/proto/output'
 @ /home/xxx/yyy/zzz/messages/proto/output/work_pb.js 11:11-37
 @ ./client.js


How do I tell webpack to look in the current path for the nod emodules, and not in the path of the compiled proto?




Aucun commentaire:

Enregistrer un commentaire