1

I want to load a local version of node-opcua with 'require' inside a HTML file, but it does not really work. The code snippet is the following:

<script type="text/javascript" src="path_to_require.js"></script>

<script> 

var opcua = require(["path_to_node-opcua"]); <!-- Yes, the path is correct >

var client = new opcua.OPCUAClient();

...

When I execute the script I get the following error in the console:

Uncaught TypeError: opcua.OPCUAClient is not a constructor

Hence, var opcua is loaded correctly, but OPCUACluent is not, although the class is declared in a file that is present in the node-opcua folder called opcua_client.js under node-opcua\lib\client\

Sources: The 'require' script from http://requirejs.org/docs/download.html#requirejs. The node-opcua folder with the console command npm install node-opcua.

MEVIS3000
  • 521
  • 3
  • 18

2 Answers2

1

node-opcua is not intended to run inside a browser as it relies on nodejs specific features such as filesystem access, crypto and so on.

Etienne
  • 16,249
  • 3
  • 26
  • 31
1

You need to use browserify if you want to use that module in client. You will also need to look at how to use browserify with file system access (it can be done if paths are known ahead of time).

chovy
  • 72,281
  • 52
  • 227
  • 295
  • browserify is what I was looking for, but unfortunately it does not work with node-opcua. I get the error `Cannot find module 'lib/nodeopcua' ... ` – MEVIS3000 Dec 14 '16 at 12:22