【问题标题】:Uncaught ReferenceError: process is not defined vuejs, vuex , Webpack SSRUncaught ReferenceError: process is not defined vuejs, vuex, Webpack SSR
【发布时间】:2019-06-13 13:43:12
【问题描述】:

当我在 webpack 中定义生产配置时出现错误

错误:

Uncaught ReferenceError: process is not defined 

类似的代码 console.log(进程)

  process.env.NODE_ENV === "production"

 if (process.env.NODE_ENV === "production") {
   module.exports.devtool = "#source-map";
   // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
     "process.env": {
       NODE_ENV: '"production"'
    }
 })

【问题讨论】:

    标签: vue.js webpack vuex server-side-rendering


    【解决方案1】:

    当我添加 Webpack.base.js -- libraryTarget: 'commonjs2' -- 就像从

    (Webpack.js 或 Webpack.base.js 或 Webpack.config.js)

     output: {
       path: path.resolve(__dirname, "./dist"),
       publicPath: "/dist/",
       filename: "build.js"
      }
    

    到

    output: {
       path: path.resolve(__dirname, "./dist"),
       publicPath: "/dist/",
       filename: "build.js",
       libraryTarget: 'commonjs2'  
      },
    

    库目标:'commonjs2' //此选项允许用户在导出包装器中插入 cmets。要为每个 libraryTarget 类型插入相同的注释,请将 assistantComment 设置为字符串:
    read more

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2019-07-24
      • 2018-08-03
      • 1970-01-01
      • 2020-04-11
      相关资源
      最近更新 更多