[英]Cannot use typescript class from other local typescript module using browserify
I have a common npm module containing TypeScript which is an node module providing some classes and functionality. 我有一个包含TypeScript的公共npm模块,这是一个提供一些类和功能的节点模块。 This module is packaged via
browserify
+ tsify
and also exports the declaration files and built with gulp. 该模块通过包装
browserify
+ tsify
还出口报关文件,并一饮而尽建成。
I have another npm module using TypeScript which imports this module locally via file:../modulename
and tries to use functionality from the first module. 我还有一个使用TypeScript的npm模块,该模块通过
file:../modulename
在本地导入该模块,并尝试使用第一个模块的功能。 The second module is also packaged via browserify
+ tsify
and built with gulp
. 第二个模块是通过包装也
browserify
+ tsify
和内置gulp
。 The compilation of the second module works via npx tsc
, but fails if I execute the gulp build file with the error message 第二个模块的编译通过
npx tsc
,但是如果执行带有错误消息的gulp构建文件,则失败
Error: Cannot find module './AbstractClass' from 'folderInOtherModuleContainingTheJSFiles'
Interestingly it sometimes fails with this Class sometimes with another, so it seems there is also some kind of concurrent processing. 有趣的是,该类有时会失败,而另一类会失败,因此似乎还存在某种并发处理。
I extracted the failing code from my project and created a minimal example with this behavior here . 我从项目中提取了失败的代码,并在此处创建了一个具有此行为的最小示例。
npm version: 5.6.0 node version: v9.5.0
For anybody who might come to this post and face the same error. 对于可能来到此职位并面临相同错误的任何人。
I opened an issue at tsify too, thinking it has something to do with the plugin, because npx tsc
worked. 我也在tsify上开了一个问题 ,认为它与插件有关,因为
npx tsc
起作用了。
Luckily the issue has been resolved, although with a workaround. 幸运的是,该问题已得到解决,尽管有解决方法。 There seems to be a name collision which causes
browserify
to think that a require
call, which is a variable, in the resulting bundle needs to be resolved, but can't. 似乎发生了名称冲突,这导致
browserify
认为需要解决结果包中的require
调用(这是一个变量),但不能解决。 The workaround is uglifying the resulting bundle, so that the conflict does not happen. 解决方法是使生成的捆绑包不正确,以免发生冲突。 More details in the above linked issue.
上述链接问题中的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.