I encountered an issue while working on my project: I kept receiving the error message "Cannot read property match
of undefined."
Cannot read property 'match' of undefined
The error points to a specific line in polyfills.js:
This error is perplexing as it doesn't specify any particular file. Could someone please take a look at this github repo for me?
https://github.com/raphael10-collab/ElectronVueTypeScriptScaffolding
Update 1)
Thanks to Elias comment, I realized that vue.config.js was messed-up. Now vue.config.is is :
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide
/guide.html#web-workers
const WorkerPlugin = require('worker-plugin')
module.exports = {
// options...
publicPath: '',
pluginOptions: {
electronBuilder: {
// Other configuration options...
nodeIntegration: true
},
configureWebpack: {
plugins: [new WorkerPlugin()]
}
}
}
Regarding nodeIntegration, I disabled it in /src/background.js because I read it is more secure to have preload.js file
This is my new webpack.config.js (it was messed up as well, like vue.config.is, with each module.exports overriding the previous one):
module.exports = {
entry: './src/background.js',
// Other webpack configurations...
}
I do not understand what should I enable here in webpack: https://webpack.js.org/plugins/define-plugin/
Update 2)
I disabled nodeIntegration in vue.config.js
vue.config.js :
// More configurations...
nodeIntegration: false
},
configureWebpack: {
plugins: [new WorkerPlugin()]
}
}
}
and defined process in webpack.config.js
webpack.config.js :
module.exports = {
entry: './src/background.ts',
// Other webpack configurations...
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
}
When running yarn electron:serve I now get Error: Cannot read property 'match' of undefined
https://i.sstatic.net/4CR5S.png
If I keep nodeIntegration:true in vue.config.js and change in src/background.js to :
// Code snippet...
when running yarn electron:serve I get this error:
"Cannot read property 'app' of undefined"</p>
<p><a href="https://i.sstatic.net/KzSdB.png" rel="nofollow noreferrer"></a></p>
<p>This is /src/store/modules/app.ts :</p>
<pre><code>import Vue from 'vue'
// Other code snippets...
export default app
But I would prefer to solve the problem while keeping nodeIntegration: false in order to keep the app safer
Update 3)
I discovered that the problem "Cannot read property match
of undefined" disappears once I comment this line
// Code snippet...
in src/background.ts :</p>
<pre><code>// Code snippet...
and db.get('settings.currentTheme') comes from this file:
src/services/electron-services/database/index.ts :
// Large code snippet...