NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.64k stars 4.8k forks source link

编译的时候某些和nodejs自带库重名的包不会被打包 #3347

Closed skymoonya closed 5 years ago

skymoonya commented 5 years ago

问题描述 比如querystring,比如Buffer

复现步骤 package.json中有如下包,在项目某个js中import这些包,会报错

{ "dependencies": { "querystring": "^0.2.0", "buffer": "^5.2.1" } }

node_modules文件夹中可以找到这些包,但是在dist/npm中找不到

期望行为dist/npm中可以找到这些包

报错信息

(node:83811) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'querystring'
    at Object.openSync (fs.js:438:3)
    at Object.readFileSync (fs.js:343:35)
    at /Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/resolve_npm_files.js:175:30
    at Generator.next (<anonymous>)
    at /Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/resolve_npm_files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/resolve_npm_files.js:3:12)
    at recursiveRequire (/Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/resolve_npm_files.js:174:12)
    at Object.resolveNpmFilesPath (/Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/resolve_npm_files.js:53:9)
    at Object.getExactedNpmFilePath (/Users/moon/.nvm/versions/node/v10.15.3/lib/node_modules/@tarojs/cli/dist/util/npmExact.js:22:45)
(node:83811) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:83811) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

系统信息

MacBook-Pro-2:c-mini-program moon$ taro info
👽 Taro v1.3.0-beta.6

  Taro CLI 1.3.0-beta.6 environment info:
    System:
      OS: macOS 10.14.5
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
      npm: 6.9.0 - ~/.nvm/versions/node/v10.15.3/bin/npm
    npmPackages:
      @tarojs/async-await: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/components: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/plugin-babel: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/plugin-csso: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/plugin-less: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/plugin-uglifyjs: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/redux: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/redux-h5: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/router: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro-alipay: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro-h5: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro-swan: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro-tt: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/taro-weapp: ^1.3.0-beta.6 => 1.3.0-beta.6 
      @tarojs/webpack-runner: ^1.3.0-beta.6 => 1.3.0-beta.6 
      eslint-config-taro: ^1.3.0-beta.6 => 1.3.0-beta.6 
      eslint-plugin-taro: ^1.3.0-beta.6 => 1.3.0-beta.6 
      nervjs: ^1.4.0 => 1.4.0
taro-bot[bot] commented 5 years ago

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

luckyadam commented 5 years ago

那就不要用这些包吧。。。找替代物

skymoonya commented 5 years ago

那就不要用这些包吧。。。找替代物

我现在就是这么解决的,但感觉这样是绕过了这个问题,官方文档也没找到相关说明

luckyadam commented 5 years ago

后续会加入说明,node 的包不要使用

taro-bot[bot] commented 5 years ago

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

drizzlezxy commented 4 years ago

在调用的时候可以显式引用依赖,告诉taro这个是npm依赖包,不是node的模块。

修改方式如下: 把require('buffer')改成require('buffer/'),import也是同理。