child_process and python-shell not working, used to work in version 1.4.5
See original GitHub issueDescribe the bug
I updated my project package.json to use latest versions. I was able to run the code, now I can’t, I don’t know which part is the problem (Vue, Electron, another component). I tested this by changing my package.json in the same environment and running npm install
.
Note: I’m not very experienced in Vue, Electron or Webpack.
This is the code I was able to run inside App.vue, I took it from another issue (don’t remember which):
<script>
import {
exec
} from 'child_process'
export default {
created() {
console.log('abc')
exec('ls -lah /tmp', function(error, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
}
}
</script>
Apparently this problem is related with running pyhton-shell also, which I want to be able to run. This is the code that was working and isn’t anymore, which is inside a Vue method for a component:
let PythonShellLibrary = require('python-shell');
let {
PythonShell
} = PythonShellLibrary;
PythonShell.run('[path]/showRandom.py', null, function(err, results) {
if (err) {
// console.log('err', err)
throw err;
}
if (results) {
console.log('results', results);
}
console.log('finished');
});
To Reproduce
I created a new project vue create project
, to create a new package.json with all the lateste stuff. I then passed that package.json into my project and did npm install
. I did some changes in background.js to allow it to work. Everything else is working (from what I can tell).
This is my working package.json:
{
"name": "scriptrunner",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"core-js": "^3.6.4",
"python-shell": "^1.0.8",
"vue": "^2.6.11",
"vue-router": "^3.1.5",
"vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.2.0",
"@vue/cli-plugin-eslint": "~4.2.0",
"@vue/cli-plugin-router": "~4.2.0",
"@vue/cli-plugin-unit-jest": "^4.3.1",
"@vue/cli-plugin-vuex": "~4.2.0",
"@vue/cli-service": "~4.2.0",
"@vue/test-utils": "1.0.0-beta.31",
"babel-eslint": "^10.0.3",
"electron": "^6.0.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.1.2",
"sass": "^1.25.0",
"sass-loader": "^8.0.2",
"vue-cli-plugin-electron-builder": "~1.4.5",
"vue-template-compiler": "^2.6.11"
}
}
The package.json that isn’t working anymore:
{
"name": "scriptrunner",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"core-js": "^3.6.5",
"python-shell": "^2.0.1",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/test-utils": "^1.0.3",
"babel-eslint": "^10.1.0",
"electron": "^9.0.0",
"electron-devtools-installer": "^3.1.1",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.4",
"vue-template-compiler": "^2.6.11"
}
}
Expected behavior
I should get this:
Instead I get this:
Error in created hook: "TypeError: Object(...) is not a function"

When running python-shell, I get:
"TypeError: child_process_1.spawn is not a function"
Environment (please complete the following information):
- Custom config for vcp-electron-builder: I don’t know what this is.
- Link to my repo: https://github.com/caballerofelipe/scriptrunner/
- Terminal output from running
vue info
:
Environment Info:
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: Not Found
npm: 6.14.8 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.125
Edge: Not Found
Firefox: 79.0
Safari: 13.1.2
npmPackages:
@ant-design-vue/babel-helper-vue-transform-on: 1.0.1
@vue/babel-helper-vue-jsx-merge-props: 1.0.0
@vue/babel-plugin-transform-vue-jsx: 1.1.2
@vue/babel-preset-app: 4.5.4
@vue/babel-preset-jsx: 1.1.2
@vue/babel-sugar-functional-vue: 1.1.2
@vue/babel-sugar-inject-h: 1.1.2
@vue/babel-sugar-v-model: 1.1.2
@vue/babel-sugar-v-on: 1.1.2
@vue/cli-overlay: 4.5.4
@vue/cli-plugin-babel: ~4.5.0 => 4.5.4
@vue/cli-plugin-eslint: ~4.5.0 => 4.5.4
@vue/cli-plugin-router: ~4.5.0 => 4.5.4
@vue/cli-plugin-unit-jest: ~4.5.0 => 4.5.4
@vue/cli-plugin-vuex: ~4.5.0 => 4.5.4
@vue/cli-service: ~4.5.0 => 4.5.4
@vue/cli-shared-utils: 4.5.4
@vue/component-compiler-utils: 3.2.0
@vue/preload-webpack-plugin: 1.1.2
@vue/test-utils: ^1.0.3 => 1.0.4
@vue/web-component-wrapper: 1.2.0
eslint-plugin-vue: ^6.2.2 => 6.2.2
jest-serializer-vue: 2.0.2
vue: ^2.6.11 => 2.6.11
vue-cli-plugin-electron-builder: ~2.0.0-rc.4 => 2.0.0-rc.4
vue-eslint-parser: 7.1.0
vue-hot-reload-api: 2.3.4
vue-jest: 3.0.6
vue-loader: 15.9.3 (16.0.0-beta.5)
vue-router: ^3.2.0 => 3.4.3
vue-style-loader: 4.1.2
vue-template-compiler: ^2.6.11 => 2.6.11
vue-template-es2015-compiler: 1.9.1
vuex: ^3.4.0 => 3.5.1
npmGlobalPackages:
@vue/cli: 4.5.4
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Just create it in the project root then.
@nklayman, thanks for your answer. Indeed it works 😉.
I read the docs and tried both approaches (
nodeIntegration: true
and preload scripts) and both work. I guess preload scripts would be better, right? A little more secure?