我正在尝试在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下载浏览器版本,将其放置到ionic项目中的静态文件夹中(我相信应该是可能的),然后将此脚本直接包含在您的主HTML页面中,或者找到另一种方式来让ionic允许你去做。
P.S。并且也许在动物群客户端回购中提出有关package.json配置不正确的问题是个好主意。