Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NasinLin opened this issue Apr 28, 2019 · 2 comments
Open

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

NasinLin opened this issue Apr 28, 2019 · 2 comments

Comments

@NasinLin
Copy link

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants