I am using a node server with express to use Portis SDK. The project structure looks like this :
├── app.js (entry) ├── node_modules ├── package.json ├── package-lock.json ├── public (static files) │ └── portis.js └── views (templates and rendering) ├── home.html └── layouts package.json
{ "name": "src", "version": "1.0.0", "description": "YYYYY", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "XXXXX", "license": "ISC", "dependencies": { "@portis/web3": "^2.0.0-beta.59", "body-parser": "^1.19.0", "cors": "^2.8.5", "express": "^4.17.1", "express-handlebars": "^5.2.0", "pm2": "^4.5.0", "web3": "^1.3.0" }, "devDependencies": { "@babel/core": "7.2.0", "@types/web3": "1.0.18", "parcel-bundler": "^1.6.1", "nodemon": "^2.0.6" } } in one of my templates (home.html),
<script src="/public/portis.js"></script> and portis.js is the same as this CodeSandBox.
When that template is served, I am getting an error:
Uncaught SyntaxError: Cannot use import statement outside a module (portis.js:1) from searching SO results to solve it, when I change home.html and adding module type to the script:
<script type="module" src="/public/portis.js"></script> (while type="module" is not used in codesanbox I copied from and it runs perfectly on that)
but it results in another error:
Uncaught TypeError: Failed to resolve module specifier "@portis/web3". Relative references must start with either "/", "./", or "../". (If I remove import "@portis/web3" then it gives the same error on the next import line)
I have tried most of the relevant solutions which I found on SO but it doesn't seem to work