Page 1 of 1
right way to import npm-module
Posted: Wed Aug 28, 2024 3:33 pm
by foxpalace
Hi, what is the standard way to use an mpm module?
PowerSwitch 2024 Spring
npm install fs-extra
old script works with: import * as fs from "fs-extra";
newly created script won't import it with this command.
Greetings
Re: right way to import npm-module
Posted: Fri Aug 30, 2024 10:39 am
by tdeschampsBluewest
Scripting within switch designer interface does not support NPM import.
Scripting within scripter (with a proper TS file) will support NPM.
On top of your main.ts file you should import your script as :
Destructuring syntax with a star (as below) tend to be less readable. Keep it only when you need partial functions of the module.
Once it's set, you still have to open a shell at the same level of your main.ts file
Code: Select all
cd "whatsoever/is/your/path/to/maints"
npm i fs-extra
Note that in VScode, you could also right click on the main.ts file in the workspace and use "Open in integrated terminal".
Hope that will help you

Re: right way to import npm-module
Posted: Tue Sep 10, 2024 2:05 pm
by foxpalace
Hi, yes I use Visual Studio Code ... 95% of my Scripts are now TypeScript ... and I have a lot. I don't know the Version of PowerSwitch (there is somewhere a Webinar) we should use require - now back to import. Sometimes works require sometimes import
