L
L
lavezzi12019-05-06 16:14:57
JavaScript
lavezzi1, 2019-05-06 16:14:57

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

1 answer(s)
A
Alexey Shashenkov, 2019-05-06
@teknik2008

Use the environment variable NODE_PATH
here is an example structure

app
 |-modules
   |-module_a  
   |-module_b
   `-module_c
 |-controllers
 `-views
 index.js

At startup, you can specify a variable NODE_PATH=./modulesand 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 question

Ask a Question

731 491 924 answers to any question