research-virtualfortknox / msb-client-websocket-nodejs

The nodeJs client library to connect to the websocket interface of the MSB (Manufacturing Service Bus)
Apache License 2.0
7 stars 5 forks source link

The statement `require.main.filename` not supported by applications using webpack #7

Closed tom3012 closed 5 years ago

tom3012 commented 5 years ago

I'm submitting a ...

Current behavior:

Cannot use the client with webpack, because require.main.filename inmsb_client.js is not supported: Look at Issue #3244 on webpack.

App threw an error during load
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:105:11)
    at Object.dirname (path.js:580:5)
    at Object../node_modules/@vfk_research/msb-client-websocket-nodejs/src/msb_client.js

Expected behavior:

Should do the job on webpack as well!?!

Steps to reproduce:

  1. Clone this boilerplate
  2. Add the msb-client
  3. Small example for calling msb:
    
    import * as MsbClient from '@vfk_research/msb-client-websocket-nodejs'

const uuid = '' const name = '' const description = '' const token = '' const type = 'Application' const msbUrl = '***'

const msbClient = new MsbClient(type, uuid, name, description, token)

export const initMsb = () => { // enable debug log messages (default = false). msbClient.enableDebug(true)

// enable data format and message data validation (default = false) // might impact performance msbClient.enableDataFormatValidation(true)

// enable auto reconnect for the client (default = false). msbClient.disableAutoReconnect(false)

// set the reconnect interval time (default = 10000 ms). msbClient.setReconnectInterval(10000)

// enable event message cache which stores messages in case of a connection loss (default = true). msbClient.disableEventCache(true)

// set event cache size (default = 1000 message events). msbClient.setEventCacheSize(1000)

// disables hostname verification for ssl (default = false). msbClient.disableHostnameVerification(true)

// get the self desctiption to see all added configs, events and functions so far console.info(JSON.stringify(msbClient.getSelfDescription(), null, 4))

// connect to the MSB websocket interface, if you call the .connect function without any // parameters, the standard values from the application.properties file will be used. msbClient.connect(msbUrl)

// register client on MSB msbClient.register() }

export const closeMsb = () => { msbClient.disconnect() }

export default msbClient

4. Call the msb in `/src/main/main.ts` for example:
```js
import { initMsb } from './msb/msb'

// hidden code

app.on('ready', () => {
  createWindow()
  initMsb()
})

// rest of the code

MSB client version: 1.0.5

MSB server version: x.y.z-RELEASE

Anything else:

My solution:

Just adding || '.' as fallback to current directory at following lines: 61, 66, 96 solves this issue. Look at this file change at node-php-fpm

ipamaas commented 5 years ago

Thanks for reporting and the included solution!

The fix is part of version 1.0.6 and can be tested.