question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

child_process and python-shell not working, used to work in version 1.4.5

See original GitHub issue

Describe 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: Screen Shot 2020-08-19 at 01 02 28

Instead I get this:

Error in created hook: "TypeError: Object(...) is not a function"
Screen Shot 2020-08-19 at 01 00 11

When running python-shell, I get:

"TypeError: child_process_1.spawn is not a function"

Environment (please complete the following information):

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nklaymancommented, Aug 20, 2020

Just create it in the project root then.

1reaction
caballerofelipecommented, Aug 20, 2020

With the 2.0.0 release, you will have to manually enable nodeIntegration, see these docs for details. That should fix your issue.

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Unable to require('child_process').spawn, console ...
I ran into this same problem trying to run code like this var spawn = require('child_process') var child = spawn('pwd') ... Use this...
Read more >
python-shell - npm
A simple way to run Python scripts from Node.js with basic but efficient inter-process communication and better error handling. Features.
Read more >
How to execute a Python script and retrieve output (data and ...
1) Using a library. In order to execute a python script easily and without effort, you can use the python-shell library to achieve...
Read more >
Python shell jobs in AWS Glue
With a Python shell job, you can run scripts that are compatible with Python 2.7, Python 3.6, or Python 3.9. You can't use...
Read more >
Electron as GUI of Python Applications (Updated)
This post shows how to use Electron as the GUI component of Python ... If properly configured, the above commands should have no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found