Open githoniel opened 6 years ago
We use exteral to load native module in dev mode
externals: [ ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)) ], output: { filename: '[name].js', libraryTarget: 'commonjs2', // ensure to compile require native module to `mdoule.exports = require('xxx')`, no `return 'xxx'` path: path.join(__dirname, '../dist/electron') },
/// index.ejs // add module globalPath require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
but in unit test, we do not have any config above
// karma.conf.js delete webpackConfig.externals delete webpackConfig.output.libraryTarget
So we can't load any native module in unit test.
we can't load any native module in unit test.
'node-ffi' is a package design for node, can't compile by webpack.
you will get error as unit test config did not treat 'node-ffi' as exterals
// karma.conf.js // don't treat dependencies as externals delete webpackConfig.entry // delete webpackConfig.externals // delete webpackConfig.output.libraryTarget preprocessors: { './index.js': ['electron', 'webpack', 'sourcemap'] },
// add this line in test/unit/index.js require('module').globalPaths.push(require('path').resolve(__dirname, '../../node_modules'))
I don't know if this will break any thing.
I've faced the same issue. Thanks for your solution. 🌹
Found an issue or bug with electron-vue? Tell me all about it!
We use exteral to load native module in dev mode
but in unit test, we do not have any config above
So we can't load any native module in unit test.
Describe the issue / bug.
we can't load any native module in unit test.
How can I reproduce this problem?
'node-ffi' is a package design for node, can't compile by webpack.
you will get error as unit test config did not treat 'node-ffi' as exterals
Tell me about your development environment.
My Solutions
I don't know if this will break any thing.