Search code examples
node.jsmsmq

NodeJS-MSMQ: SyntaxError: Cannot use import statement outside a module


I'm pretty new with NodeJS and I'm trying to use a module called "updated-node-msmq" (from this repository) in my project but getting an error.

What I've done:

  1. I opened a new folder for the project.
  2. I used the command "$ npm install --save updated-node-msmq" and got some warnings (Screenshot attached).
  3. When I try to use the module according to the README, and run my "test.js" file I got the following error here in the screenshot).

I am using version 14.16.0 of NodeJS and after trying to fix this myself I realized that probably the problem is that the module was built for older versions of NodeJS. I understand that low version is not a recommended solution, but I have no clue how to update a module.

Help / guidance in solving the problem? Thanks in advance everyone!


Solution

  • Why are you using updated-node-msmq? That package seems like a mess, and the errors you are getting is because the whole module is written with ES2015 but doesn't seem to have been transpiled to node.js compatible code before published to NPM.

    I'd advise you to use a tried and tested module for MSMQ first and foremost.

    EDIT: Seems like the author fucked up in the 0.2.0 version. You could use the 0.1.9 (by instead using npm install updated-node-msmq@0.1.9 but that one is 3 years old.