node-machine-id报错 Can't resolve "child_process"解决方法

在Vue中导入node-machine-id后显示Can't resolve "child_process" image 解决方法:

  1. 安装webpack(npm install webpack)

  2. 在vue.config.js添加如下代码

    const { machineId, machineIdSync } = require('node-machine-id')
    const webpack = require('webpack')
    module.exports = {
    configureWebpack: {
     plugins: [
       new webpack.DefinePlugin({
         VERSION: JSON.stringify(machineIdSync({original: true}))
       })
     ],
    }
    }
    
    

let id = machineIdSync({original: true})


3. 在main.js添加

Vue.prototype.$VERSION = VERSION


4. 在组件中通过

this.$VERSION

``` 即可调用id

  1. 示例 image image

参考 https://www.cnblogs.com/fanjlqinl/p/14819599.html

评论

暂无评论