Search code examples
javascripthtmlnode.jsrequirenode-opcua

Require is not working for node-opcua


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.


Solution

  • 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.