Search code examples
npmvuejs3nuxt3.jspdfmake

After npm run build, fail to run. Error [ERR_MODULE_NOT_FOUND]: Cannot find module. Did you mean to import pdfmake/build/pdfmake.js?


please do your magic. I am using Nuxt3, and use pdfmake library in it. I have successfully built the project with command: npm run build

When I run it with: npm run dev, it works normally. But after I built it, then I tried to run it with: node .output/server/index.mjs. It occurs error like on the screenshot below.

I have no clue at all, I don't know how to fix it. Please guys help, I am very open to another alternative solution. Thank you so much.


Solution

  • In the code, I import it like this:

    import pdfMake from "pdfmake/build/pdfmake";
    

    it failed. But after I change it to this:

    import pdfMake from "pdfmake/build/pdfmake.js";
    

    it works.

    I have no idea how it be like that. Someone may be can explain, please?