question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getting SyntaxError: Cannot use import statement outside a module while running in deployed java app

See original GitHub issue

I need to run a simple node app from my Java project that expose one function. I followed the logic on the documentation “Interact with Node.js” part and in local everything works, but when I try to do the same in the deployed java app I get SyntaxError: Cannot use import statement outside a module when doing nodeRuntime.getExecutor(codeFile).executeVoid();

I already tried to put “type”: “module” in package.json or change the extension to .mjs without success.

this is the package.json:

{
  "name": "banca_pdf",
  "version": "1.0.0",
  "description": "script to generate banca pdf",
  "main": "pdf.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "pak1989",
  "license": "ISC",
  "dependencies": {
    "pdfmake": "^0.2.4"
  },
  "devDependencies": {
    "@types/pdfmake": "^0.1.21"
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
caoccaocommented, Mar 18, 2022

Nice work and thank you for sharing your solution with the community.

0reactions
pak1989commented, Mar 18, 2022

In the end I made it work with I think the option 1. I had to point to the library with his absolute path in the js file, went back and made the package.json look like this:

{
  "name": "banca_pdf",
  "version": "1.0.0",
  "description": "script to generate banca pdf",
  "main": "pdf.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "pak1989",
  "license": "ISC",
  "dependencies": {
    "pdfmake": "^0.2.4"
  }
}

The way I call it in Java is the same as the express server example.

Thanks for the inputs!

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Cannot use import statement outside a module
But that gets me another error: "Error: Plugin/Preset files are not allowed to export objects, only functions." Here are the dependencies I ...
Read more >
Fix "cannot use import statement outside a module" in ...
This results in the error "Uncaught SyntaxError: cannot use import statement outside a module". If you've run into this error, it's possible ...
Read more >
Cannot use import statement outside a module - YouTube
Are you using imports in a node.js application and running into the SyntaxError : Cannot use import statement outside a module error?
Read more >
Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >
How to fix 'Uncaught SyntaxError: Cannot use import ...
In this quick guide we'll look at how you can solve the very common error, “Uncaught SyntaxError: Cannot use import statement outside a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found