nickdesaulniers / node-nanomsg

Node.js binding for nanomsg
MIT License
402 stars 70 forks source link

TypeError: Path must be a string. Received undefined #204

Open NasinLin opened 5 years ago

NasinLin commented 5 years ago

Hi, I'm using nanomsg lib to run nodejs is success and then I want to use webpack to build nodejs is ok , but I can't run js after build.

I get error message .

path.js:28
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^
TypeError: Path must be a string. Received undefined
    at assertPath (path.js:28:11)
    at dirname (path.js:1349:5)
    at Function.a.getRoot (/home/user/test-node-webpack/main.js:314:24398)
    at a (/home/user/test-node-webpack/main.js:314:23596)
    at Object.<anonymous> (/home/user/test-node-webpack/main.js:314:15280)
    at i (/home/user/test-node-webpack/main.js:1:172)
    at Object.<anonymous> (/home/user/test-node-webpack/main.js:154:2238)
    at i (/home/user/test-node-webpack/main.js:1:172)
    at /home/user/test-node-webpack/main.js:1:964
    at Object.<anonymous> (/home/user/test-node-webpack/main.js:1:974)

How can I resolve the error?

nickdesaulniers commented 5 years ago

sounds like you're holding webpack wrong. How can I reproduce the issue you're observing, as it looks like a failure from webpack, and it's not clear how node-nanomsg is related?

NasinLin commented 5 years ago

This is my webpack.config file

const path = require('path');

module.exports = {
  target: 'node',
  mode: 'production',
  entry: './index.js',
  output: {
    path: path.resolve(__dirname, ''),
    filename: 'main.js'
  },
  module: {
    rules: [{
      test: /\.m?js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['@babel/preset-env']
        }
      }
    }]
  }
};

This is my index file

const commandLineArgs = require('command-line-args');
const fs = require('fs');
const nano = require('nanomsg');
const server = nano.socket('rep');

const optionDefinitions = [{
  name: 'config',
  alias: 'c',
  type: String
}];

const options = commandLineArgs(optionDefinitions);

if (!options.config) {
  console.log('no options');
  process.exit(0);
}

const config = JSON.parse(fs.readFileSync(options.config).toString());
console.log(JSON.stringify(config));

When I remove this line "require('nanomsg')" , It's working is fine