[英]Module not found: Error: Can't resolve 'http' in FaunaDB JavaScript Driver
我正在嘗試在 Ionic 項目中使用 FaunaDB,但出現了一個我不知道如何解決的問題。
我只是創建了一個新項目並安裝了驅動程序:
ionic start --type=angular my-app blank
npm i faunadb
然后,我實例化 FaunaDB.Cliente:
import * as FaunaDB from 'faunadb';
const client = new FaunaDB.Client({
secret: environment.faunadb.secret,
keepAlive: false,
});
在開發中運行良好,但是當我為生產構建時:使用此命令:
ionic build --prod
並發生以下錯誤:
ERROR in ../node_modules/faunadb/src/Client.js
Module not found: Error: Can't resolve 'http' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
resolve 'http' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
Parsed request is a module
using description file: D:\Workspace\www\fanstore\workspace\node_modules\faunadb\package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in D:/Workspace/www/fanstore/workspace/my-app/
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: ./http)
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\http doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\http.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\http.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\http.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\http.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\my-app\http doesn't exist
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\node_modules doesn't exist or is not a directory
D:\Workspace\www\node_modules doesn't exist or is not a directory
D:\Workspace\node_modules doesn't exist or is not a directory
D:\node_modules doesn't exist or is not a directory
looking for modules in D:\Workspace\www\fanstore\workspace\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\http doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\http.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\http.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\http.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\http.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\node_modules\http doesn't exist
[D:\Workspace\www\fanstore\workspace\my-app\http]
[D:\Workspace\www\fanstore\workspace\my-app\http.ts]
[D:\Workspace\www\fanstore\workspace\my-app\http.tsx]
[D:\Workspace\www\fanstore\workspace\my-app\http.mjs]
[D:\Workspace\www\fanstore\workspace\my-app\http.js]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\node_modules]
[D:\Workspace\www\fanstore\node_modules]
[D:\Workspace\www\node_modules]
[D:\Workspace\node_modules]
[D:\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\http\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\http]
[D:\Workspace\www\fanstore\workspace\node_modules\http.ts]
[D:\Workspace\www\fanstore\workspace\node_modules\http.tsx]
[D:\Workspace\www\fanstore\workspace\node_modules\http.mjs]
[D:\Workspace\www\fanstore\workspace\node_modules\http.js]
@ ../node_modules/faunadb/src/Client.js 87:8-23
@ ../node_modules/faunadb/index.js
@ ./src/app/app.component.ts
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ../node_modules/faunadb/src/Client.js
Module not found: Error: Can't resolve 'https' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
resolve 'https' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
Parsed request is a module
using description file: D:\Workspace\www\fanstore\workspace\node_modules\faunadb\package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in D:/Workspace/www/fanstore/workspace/my-app/
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: ./https)
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\https doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\https.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\https.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\https.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\https.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\my-app\https doesn't exist
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\node_modules doesn't exist or is not a directory
D:\Workspace\www\node_modules doesn't exist or is not a directory
D:\Workspace\node_modules doesn't exist or is not a directory
D:\node_modules doesn't exist or is not a directory
looking for modules in D:\Workspace\www\fanstore\workspace\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\https doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\https.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\https.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\https.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\https.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\node_modules\https doesn't exist
[D:\Workspace\www\fanstore\workspace\my-app\https]
[D:\Workspace\www\fanstore\workspace\my-app\https.ts]
[D:\Workspace\www\fanstore\workspace\my-app\https.tsx]
[D:\Workspace\www\fanstore\workspace\my-app\https.mjs]
[D:\Workspace\www\fanstore\workspace\my-app\https.js]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\node_modules]
[D:\Workspace\www\fanstore\node_modules]
[D:\Workspace\www\node_modules]
[D:\Workspace\node_modules]
[D:\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\https\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\https]
[D:\Workspace\www\fanstore\workspace\node_modules\https.ts]
[D:\Workspace\www\fanstore\workspace\node_modules\https.tsx]
[D:\Workspace\www\fanstore\workspace\node_modules\https.mjs]
[D:\Workspace\www\fanstore\workspace\node_modules\https.js]
@ ../node_modules/faunadb/src/Client.js 86:8-24
@ ../node_modules/faunadb/index.js
@ ./src/app/app.component.ts
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ../node_modules/faunadb/src/errors.js
Module not found: Error: Can't resolve 'util' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
resolve 'util' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
Parsed request is a module
using description file: D:\Workspace\www\fanstore\workspace\node_modules\faunadb\package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in D:/Workspace/www/fanstore/workspace/my-app/
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: ./util)
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\my-app\util doesn't exist
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\node_modules doesn't exist or is not a directory
D:\Workspace\www\node_modules doesn't exist or is not a directory
D:\Workspace\node_modules doesn't exist or is not a directory
D:\node_modules doesn't exist or is not a directory
looking for modules in D:\Workspace\www\fanstore\workspace\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\node_modules\util doesn't exist
[D:\Workspace\www\fanstore\workspace\my-app\util]
[D:\Workspace\www\fanstore\workspace\my-app\util.ts]
[D:\Workspace\www\fanstore\workspace\my-app\util.tsx]
[D:\Workspace\www\fanstore\workspace\my-app\util.mjs]
[D:\Workspace\www\fanstore\workspace\my-app\util.js]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\node_modules]
[D:\Workspace\www\fanstore\node_modules]
[D:\Workspace\www\node_modules]
[D:\Workspace\node_modules]
[D:\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\util\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\util]
[D:\Workspace\www\fanstore\workspace\node_modules\util.ts]
[D:\Workspace\www\fanstore\workspace\node_modules\util.tsx]
[D:\Workspace\www\fanstore\workspace\node_modules\util.mjs]
[D:\Workspace\www\fanstore\workspace\node_modules\util.js]
@ ../node_modules/faunadb/src/errors.js 3:11-26
@ ../node_modules/faunadb/index.js
@ ./src/app/app.component.ts
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ../node_modules/faunadb/src/values.js
Module not found: Error: Can't resolve 'util' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
resolve 'util' in 'D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src'
Parsed request is a module
using description file: D:\Workspace\www\fanstore\workspace\node_modules\faunadb\package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in D:/Workspace/www/fanstore/workspace/my-app/
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: D:\Workspace\www\fanstore\workspace\my-app\package.json (relative path: ./util)
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\my-app\util.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\my-app\util doesn't exist
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\workspace\node_modules\node_modules doesn't exist or is not a directory
D:\Workspace\www\fanstore\node_modules doesn't exist or is not a directory
D:\Workspace\www\node_modules doesn't exist or is not a directory
D:\Workspace\node_modules doesn't exist or is not a directory
D:\node_modules doesn't exist or is not a directory
looking for modules in D:\Workspace\www\fanstore\workspace\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
D:\Workspace\www\fanstore\workspace\node_modules\util.js doesn't exist
as directory
D:\Workspace\www\fanstore\workspace\node_modules\util doesn't exist
[D:\Workspace\www\fanstore\workspace\my-app\util]
[D:\Workspace\www\fanstore\workspace\my-app\util.ts]
[D:\Workspace\www\fanstore\workspace\my-app\util.tsx]
[D:\Workspace\www\fanstore\workspace\my-app\util.mjs]
[D:\Workspace\www\fanstore\workspace\my-app\util.js]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\src\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\faunadb\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\node_modules]
[D:\Workspace\www\fanstore\node_modules]
[D:\Workspace\www\node_modules]
[D:\Workspace\node_modules]
[D:\node_modules]
[D:\Workspace\www\fanstore\workspace\node_modules\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\util\package.json]
[D:\Workspace\www\fanstore\workspace\node_modules\util]
[D:\Workspace\www\fanstore\workspace\node_modules\util.ts]
[D:\Workspace\www\fanstore\workspace\node_modules\util.tsx]
[D:\Workspace\www\fanstore\workspace\node_modules\util.mjs]
[D:\Workspace\www\fanstore\workspace\node_modules\util.js]
@ ../node_modules/faunadb/src/values.js 7:11-26
@ ../node_modules/faunadb/index.js
@ ./src/app/app.component.ts
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
[ERROR] An error occurred while running subprocess ng.
ng.cmd run app:build:production exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
我對離子一無所知,但看起來你要從客戶端使用動物群,而不是從服務器? 在文檔中,他們建議直接通過 CDN https://docs.fauna.com/fauna/current/drivers/javascript#browsers包含客戶端版本,也許它無法通過您的捆綁程序按預期工作。 我看到它抱怨“字段'瀏覽器'不包含有效的別名配置”,這意味着 package.json 未按照捆綁程序的預期配置。 實際上根本沒有這樣的字段: https://github.com/fauna/faunadb-js/blob/master/package.json所以,如果 ionic 允許它,你可以從 CDN 下載瀏覽器構建,把它放到 ZA8122259CEF8E953C ionic 項目中的文件夾(我相信它應該是可能的)並將此腳本直接包含在您的主 HTML 頁面中,或者找到另一種方式 ionic 如何讓您這樣做。
PS,也許在動物客戶端回購中提出關於 package.json 配置不正確的問題是個好主意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.