Search code examples
vue.jswebpackelectronvue-cli-3pty

./node_modules/node-pty/build/Release/pty.node Module parse failed: Unexpected character ''


I am trying to use the library node-pty in a project scaffolded with vue-cli. When I launch the program I get the following error:

error in ./node_modules/node-pty/build/Release/pty.node

Module parse failed: Unexpected character '' (1:0) 
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders 
(Source code omitted for this binary file)

@ ./node_modules/node-pty/lib/index.js 49:49-85 
@ ./src/background.js

Steps to reproduce

vue create test-project
cd test-project && vue add electron-builder
npm i node-pty@beta

add import pty from 'node-pty’ to src/background.js

npm run electron:serve

What I have attempted

I have attempted to add node-loader and raw-loader to the vue.config.js file

configureWebpack: {
  chainWebpack: config => {
    config.module
      .rule('node')
      .test(/.node$/i)
      .use('node-loader')
      .loader('node-loader')
      .end()
  }
}

This does not resolve the issue.


Solution

  • vue.config.js requires the use of module.exports

    module.exports = {
      chainWebpack: config => {
        config.module
          .rule('node')
          .test(/\.node$/)
          .use('node-loader')
          .loader('node-loader')
          .end();
      }
    }