简体   繁体   English

无法使用browserify从其他本地打字稿模块使用打字稿类

[英]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.

相关问题 使用带有TypeScript的browserify包含节点模块 - Using browserify with typescript to include a node module Typescript 类从其他类扩展不能用作接口属性 - Typescript class extends from other class cannot be used as interface attributes 无法在后端使用 typescript 的模块外部使用导入语句 - Cannot use import statement outside a module using typescript on backend TypeScript从其他模块调用静态函数 - TypeScript call static function from other module 将已编译的 Typescript 文件相互导入时出现“未捕获的语法错误:无法在模块外使用 import 语句” - “Uncaught SyntaxError: Cannot use import statement outside a module” when importing compiled Typescript files to each other 找不到模块“打字稿” - Cannot find module 'typescript' “不能在模块外使用 import 语句” - JavaScript 模块导入到 TypeScript 文件中,JavaScript 模块内有其他导入 - "Cannot use import statement outside of module" - JavaScript module imported into TypeScript file, JavaScript module has other imports within 使用Browserify和Typescript中的源映射进行Webstorm调试 - Webstorm debugging with source maps from Browserify and Typescript AngularJS Typescript导出模块错误类 - AngularJS typescript export class from module error 另一个项目/模块的TypeScript导入类? - TypeScript import class from another project / module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM