简体   繁体   English

在 nodejs 中从本地导入作用域包

[英]import scoped package from local in nodejs

Currently we have multiple node package published in this format目前我们有多个以这种格式发布的节点包

  • @company/module1 @公司/模块1
  • @company/module2 @公司/模块2

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.从我的其他文件夹加载,而不是从 node_modules 安装中查看。

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.我对这个问题有点困惑,猜测react-native标签是多余的。

You can't import the modules/libraries/single file, etc. in the node.js with the common import statement import Example from "package" .您不能使用通用导入语句import Example from "package"node.js导入模块/库/单个文件等。

So, try to use the const Example = require('package') instead.因此,请尝试使用const Example = require('package')代替。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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