Electron-vue: build:web catch process is not defined

Created on 30 May 2018  ·  4Comments  ·  Source: SimulatedGREG/electron-vue

Found an issue or bug with electron-vue? Tell me all about it!

Questions regarding how to use electron or vue are likely to be closed as they are not direct issues with this boilerplate. Please seek solutions from official documentation or their respective communities.

Describe the issue / bug.

#

# Install vue-cli and scaffold boilerplate
npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project

# Install dependencies and run your app
cd my-project
npm install

npm run build:web

then open ~/my-project/dist/web/index.html with google chrome, catch exception

Uncaught ReferenceError: process is not defined
    at index.html:1
How can I reproduce this problem?
# Install vue-cli and scaffold boilerplate
npm install -g vue-cli
vue init simulatedgreg/electron-vue my-project

# Install dependencies and run your app
cd my-project
npm install

npm run build:web
If visual, provide a screenshot.

image

Tell me about your development environment.
  • Node version: v9.10.1
  • NPM version: 5.6.0
  • vue-cli version: (if necessary)
  • Operating System: MacOS 10.11.6

Most helpful comment

Sorry @SimulatedGREG but how is this not an issue? The project provides a way to build for the web that isnt working because of process not being defined?

All 4 comments

This isn't an issue. The boilerplate template uses process to get the current node and electron versions, but since those don't exist in a web browser you are getting this error. In your real app, where this original landing page doesn't exist anymore, you won't have this error log.

Hay,How do I inject js to access variables by building different environments?
What I am now is

build.js

require('./build-config') //add

build-config

'use strict'
const config = require('../config/index.js')
const CONFIG_NAME = process.env.CONFIG_NAME || 'dev'

process.env.CONFIG = "custom cfg"
for (let i in config[CONFIG_NAME]) {
  process.env['CONFIG_' + i] = config[CONFIG_NAME][i]
}

package.json => scripts

 "build:alpha": "cross-env CONFIG_NAME=alpha node .electron-vue/build.js && electron-builder",

and js use variables

const service = axios.create({
  baseURL: process.env.CONFIG_BASE_API, 
  contentType: 'application/json',
  method:'get',
  withCredentials: false,
  timeout: 15000
});

use npm run dev can work,

but use npm run build run app does't work
Print via console process.env
image

thks~

Sorry @SimulatedGREG but how is this not an issue? The project provides a way to build for the web that isnt working because of process not being defined?

In my case dotenv-webpack is not working as well.

Was this page helpful?
0 / 5 - 0 ratings