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
right way to import npm-module
- tdeschampsBluewest
- Member
- Posts: 127
- Joined: Tue Jun 01, 2021 11:57 am
Re: right way to import npm-module
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
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
Scripting within scripter (with a proper TS file) will support NPM.
On top of your main.ts file you should import your script as :
Code: Select all
import fse from "fs-extra"
Code: Select all
import { tmpdir } from "tmp"
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
Hope that will help you

Do you like the Enfocus Apps developed by Bluewest?
Feel free to leave a comment on the Appstore!
Feel free to leave a comment on the Appstore!
Re: right way to import npm-module
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 
