Reputation: 131
I am trying to include mongoose in a Vue CLI app with electron-builder, but as soon as I require mongoose, I am receiving a bunch of loader errors. Does anyone else have this problem?
Steps to reproduce:
(vue-cli version 5.0.8 latest)
vue create my-project (v.3 / babel,sass,vuex,router / no history mode)
cd my-project
vue add electron-builder (v.13)
yarn add mongoose
In background.js
const mongoose = require('mongoose')
Node Version: 16.20.2
error in ./node_modules/bson/lib/bson.mjs
Module parse failed: Cannot use keyword 'await' outside an async function (131:26) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
| }
> const nodejsRandomBytes = await (async () => {
| try {
| return (await import('crypto')).randomBytes;
@ ./node_modules/mongoose/lib/types/objectid.js 13:17-32
@ ./node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js
@ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
@ ./node_modules/mongoose/lib/index.js
@ ./node_modules/mongoose/index.js
@ ./src/background.js
@ multi ./src/background.js
EDIT: I found that upgrading electron and putting mongoose in the electronBuilder.externals array it works now.
Upvotes: 1
Views: 116
Reputation: 131
I found that upgrading electron to latest and putting mongoose in the electronBuilder.externals array in vue.config.js has it working now.
Upvotes: 0