Closed mdodge-ecgrow closed 4 years ago
Installing globally won't work, it needs to be local to the project (i.e. standard npm install
, not npm install -g
.
It also looks like you may have "type": "module"
in your package.json
file. The error you're receiving is caused by the use of CommonJS syntax in an ES Modules environment.
You should be able to change the first line of your script to:
import { Service } from 'node-windows'
I haven't tested ES Modules with this library, but Node 14.x.x and above has been handling them pretty well (in general).
Also, you can delete the --harmony
option in nodeOptions
. That's an old flag, long gone in versions of Node which support ES Modules.
Figured it out!!! Main issue was here: script: 'C:\Web\\Webs\\NodeTest\\server.js',
. I was missing the double slash on the first seperator. I also had to remove type:module
from the package.json. Also, you were right, it did not work globally.
I did try leaving that line type:module
in there and using the import option instead of the require. I got this error: SyntaxError: The requested module 'node-windows' does not provide an export named 'Service'
.
I could have sworn last time I did this, I believe it was in April, I had it installed globally and the type:module
was in there. Because I just copied the files from my previous node service verbatim.
Oh well, it's working good. Thanks for your help and all your work on this project!!
Update: OK, I think I just figured out why I had the type:module
in my old node project. I needed to remove it to create the service, but I need it in there to actually run the service because I am using import
statements in my code.
@mdodge-ecgrow glad you got it working.
Right, there wouldn't be a named export, so the example I provided above would have been incorrect. It should be:
import whatever from 'node-windows'
var svc = new whatever.Service({...})
I am trying to install a Node service in Windows. I know I did this before and I don't believe I ran into this issue. Here is my service-install.js:
And I've installed node-windows globally. So I open a command prompt, cd to the the NodeTest folder and run
node service-install.js
and I get back:What am I doing wrong?