【发布时间】:2021-02-19 04:19:38
【问题描述】:
我做了一个测试项目,只尝试包含 https。我用expo init test初始化项目,然后npm install https安装库。
然后我编辑了 App.js 并在最顶部添加了这一行:import {https} from 'https';
终于expo start启动了expo server。
现在我收到以下错误:
InternalError Metro has encountered an error: While trying to resolve module `https` from file `/path/test/App.js`, the package `/path/test/node_modules/https/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/path/test/node_modules/https/index.js`. Indeed, none of these files exist:
* /path/test/node_modules/https/index.js(.native|.android.expo.ts|.native.expo.ts|.expo.ts|.android.expo.tsx|.native.expo.tsx|.expo.tsx|.android.expo.js|.native.expo.js|.expo.js|.android.expo.jsx|.native.expo.jsx|.expo.jsx|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.wasm|.native.wasm|.wasm)
* /path/test/node_modules/https/index.js/index(.native|.android.expo.ts|.native.expo.ts|.expo.ts|.android.expo.tsx|.native.expo.tsx|.expo.tsx|.android.expo.js|.native.expo.js|.expo.js|.android.expo.jsx|.native.expo.jsx|.expo.jsx|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.wasm|.native.wasm|.wasm)
我已经验证这些文件确实不存在,这里是ls node_modules/https的输出:package.json
所以我猜我在安装过程中做错了什么,但是,我不知道是什么。 (我也尝试过多次使用yarn add https安装,我得到了同样的错误)
【问题讨论】:
-
安装
https库后是否重启了metro? -
@MaksymBezruchko 是的。
-
您是否尝试将其作为默认模块导入:
import https from 'https';? -
@MaksymBezruchko 是的。
标签: javascript android node.js react-native npm