Answer the question
In order to leave comments, you need to log in
How to pass a path outside of node_modules to require()?
Hello.
There is an npm module, it has a require(`${path}/*.${ext}`) file to process. Further, having installed this module in the project, I need to pass the path to the files as a string to this requrie (). How to do it? Now I am getting an error
Cannot find module '/src/assets/icons/chevron-down.svg'
Answer the question
In order to leave comments, you need to log in
Use the environment variable NODE_PATH
here is an example structure
app
|-modules
|-module_a
|-module_b
`-module_c
|-controllers
`-views
index.js
NODE_PATH=./modules
and access the folders in the modules folder, as if they were in node_modules
. Also, if you have webpack, you can set up aliases
or access from the root through @import moduleA from '@/modules/module_a'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question