简体   繁体   中英

import scoped package from local in nodejs

Currently we have multiple node package published in this format

  • @company/module1
  • @company/module2

I would like to be able to load these module from local without installing it so we can modify the code directly.

So I make the link in the folder tree like this

- company/
-- module1 -> ../../module1  
-- module2 -> ../../module2

Now I want when I import from the scoped name, it will load from local files instead

import module1 from '@company/module1'

Load from my other folder instead of looking from node_modules instalations.

Can anyone help me on this? Thank you very much.

I'm a bit confused with the question and guess that react-native tag is redundant.

You can't import the modules/libraries/single file, etc. in the node.js with the common import statement import Example from "package" .

So, try to use the const Example = require('package') instead.

const module1 = require("path/to/the/module1");
const module2 = require("path/to/the/module2");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM