0

对于我正在处理的 typescript stenciljs 项目,我在依赖项之间的交互rollup-plugin-node-builtins以及node-gyp-build在依赖项中使用的交互方面遇到了问题。为了解决它,我能够对汇总插件进行一些更改并将其设置为模板中的自定义纱线分辨率

"resolutions": {
    "@stencil/core/**/rollup-plugin-node-builtins": "https://github.com/Matthew-Smith/rollup-plugin-node-builtins.git"
}

当我在本地运行它时效果很好,但是我们的构建过程在执行时没有可用的 gityarn install所以我们尝试将分辨率设置为.tar.gz插件的版本:

"resolutions": {
  "@stencil/core/**/rollup-plugin-node-builtins": "https://github.com/Matthew-Smith/rollup-plugin-node-builtins/archive/v2.1.3.tar.gz"
}

这似乎正确地将代码克隆到 node_modules 中:

> l node_modules | grep rollup
drwxr-xr-x    8 matthewsmith  staff   256B Jan  9 11:26 rollup
drwxr-xr-x    9 matthewsmith  staff   288B Jan  9 11:26 rollup-plugin-commonjs
drwxr-xr-x   13 matthewsmith  staff   416B Jan  9 11:26 rollup-plugin-node-builtins
drwxr-xr-x    8 matthewsmith  staff   256B Jan  9 11:26 rollup-plugin-node-resolve
drwxr-xr-x    7 matthewsmith  staff   224B Jan  9 11:26 rollup-pluginutils

> l node_modules/rollup-plugin-node-builtins
total 64
drwxr-xr-x   13 matthewsmith  staff   416B Jan  9 11:26 .
drwxr-xr-x  670 matthewsmith  staff    21K Jan  9 11:26 ..
-rw-r--r--    1 matthewsmith  staff    36B Jan  9 11:13 .babelrc
-rw-r--r--    1 matthewsmith  staff   650B Jan  9 11:13 .eslintrc
-rw-r--r--    1 matthewsmith  staff     5B Jan  9 11:13 .gitignore
-rw-r--r--    1 matthewsmith  staff    14B Jan  9 11:13 .npmignore
drwxr-xr-x    5 matthewsmith  staff   160B Jan  9 11:26 browser-test
-rw-r--r--    1 matthewsmith  staff   500B Jan  9 11:13 build-constants.js
-rw-r--r--    1 matthewsmith  staff   1.3K Jan  9 11:13 package.json
-rw-r--r--    1 matthewsmith  staff   2.5K Jan  9 11:13 readme.md
-rw-r--r--    1 matthewsmith  staff   216B Jan  9 11:13 rollup.config.js
drwxr-xr-x    4 matthewsmith  staff   128B Jan  9 11:26 src
drwxr-xr-x    4 matthewsmith  staff   128B Jan  9 11:26 test

但是当我尝试构建代码时,我得到了这个输出:

$ sd concurrent "stencil build --dev --watch" "stencil-dev-server"
[26:41.1]  @stencil/core v0.12.4 
[26:41.2]  build, app, dev mode, started ...
[26:41.7]  transpile started ...
[26:43.8]  transpile finished in 2.07 s
[26:43.8]  module map started ...
[26:43.8]  generate styles started ...
[26:43.8]  module map finished in 12 ms
[26:43.9]  generate styles finished in 76 ms

[ ERROR ]  Cannot find module 'rollup-plugin-node-builtins' at Function.Module._resolveFilename
           (internal/modules/cjs/loader.js:580:15) at Function.Module._load
           (internal/modules/cjs/loader.js:506:25) at Module.require (internal/modules/cjs/loader.js:636:17) at
           require (internal/modules/cjs/helpers.js:20:18) at
           /Users/matthewsmith/penfield/node_modules/@stencil/core/dist/compiler/index.js:18322:26
           at Generator.next (<anonymous>) at
           /Users/matthewsmith/penfield/node_modules/@stencil/core/dist/compiler/index.js:18306:71
           at new Promise (<anonymous>) at __awaiter$13
           (/Users/matthewsmith/penfield/node_modules/@stencil/core/dist/compiler/index.js:18302:12)
           at createBundle
           (/Users/matthewsmith/penfield/node_modules/@stencil/core/dist/compiler/index.js:18310:12)

是否有使用压缩档案进行纱线分辨率的特殊过程?

编辑

这是我的 yarn.lock 对于这个依赖项的样子:

rollup-plugin-node-builtins@2.1.2, "rollup-plugin-node-builtins@https://github.com/Matthew-Smith/rollup-plugin-node-builtins/archive/v2.1.3.tar.gz":
  version "2.1.3"
  resolved "https://github.com/Matthew-Smith/rollup-plugin-node-builtins/archive/v2.1.3.tar.gz#af40f65e716e2c62e698cbea169127f9c1717e7d"
  dependencies:
    browserify-fs "^1.0.0"
    buffer-es6 "^4.9.2"
    crypto-browserify "^3.11.0"
    process-es6 "^0.11.2"

纱线版本:

1.12.3
节点版本:
10.12.0
模板版本:
0.12.4
4

1 回答 1

1

所以我能够解决这个问题,尽管我并不真正理解为什么它首先作为 git 依赖项工作。

更深入地看,我注意到 package.json 将主要内容列为:

"main": "dist/rollup-plugin-node-builtins.cjs.js",

并且有一个构建包的脚本:

"build": "rollup -c -f cjs -o dist/rollup-plugin-node-builtins.cjs.js && rollup -c -f es -o dist/rollup-plugin-node-builtins.es6.js && node build-constants.js",

所以我执行了构建,通过它打包它npm pack .,然后在我的依赖解决方案中使用该压缩文件!

注意:在了解npm pack .我尝试使用之前tar -czvf,这给了我和以前一样的错误。

于 2019-01-10T04:27:54.757 回答