how can I install an import a library?

how can I install an import a library? for example import html2pdf from 'html2pdf.js';
2 Replies
kapa.ai
kapa.ai5d ago
Hi @pollastrepiupiu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To install and import a library like html2pdf.js in your Wasp project, you need to follow these steps: Installing the Library In a Wasp project, dependencies are managed through the standard package.json file at the root of your project. To add a new package, use npm:
npm install html2pdf.js
npm install html2pdf.js
This command will add the package to the dependencies section of your package.json file Project Dependencies. Importing the Library After installation, you can import the library in your JavaScript or TypeScript files using either named exports or default exports, depending on how the library is structured. For html2pdf.js specifically, you would import it using default import syntax:
import html2pdf from 'html2pdf.js';
import html2pdf from 'html2pdf.js';
Important Notes 1. Version Compatibility: If Wasp is already using a certain dependency internally with a specific version, you cannot use a different version of that same dependency. If you try to do so, you'll get an error message indicating which exact version you must use Project Dependencies. 2. Node.js Requirements: Ensure you have Node.js version 18 or higher installed on your machine Quick Start Requirements. 3. Import Styles: While Wasp currently uses and recommends default exports in its generated code, there are ongoing discussions about potentially moving toward named exports for better developer experience and tooling support. Both styles are supported in your code Github Issue on Exports. After installing and importing the library, you can use it according to its documentation in your Wasp project components or functions. GitHub: Kapa AI ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @pollastrepiupiu, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
pollastrepiupiu
pollastrepiupiuOP5d ago
Thanks!

Did you find this page helpful?