heavysixer / node-pptx

Generate PPTX files on the server-side with JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems calling the library front next.js

rundro opened this issue · comments

commented

Hello - I'm running into this error when the node function is being called from a next.js runtime. My file/function works fine when calling directly from node, but it appears to fail to load based on a file path:

  • error unhandledRejection: Error: ENOENT: no such file or directory, open '/Users/username/dev/app/.next/server/app/api/endpoint/../fragments/[Content_Types].xml'

It seems like the next.js runtime is a different path than the node_modules or the Content_Types.xml. I have tried putting the fragments directory in public and fetching the file, i have tried absolute paths, I'm not sure why it's not working when being called by the API. I found the reference in this file which could be causing the issue:

node-pptx/fragments/[Content_Types].xml

    build() {
        xml2js.parseString(fs.readFileSync(`${__dirname}/../fragments/[Content_Types].xml`), (err, js) => {
            this.content['[Content_Types].xml'] = js;
        });

        this.addDefaultMediaContentTypes();
    }
commented

Fixed this by modifying my next.config.js to include experimental serverComponentsExternalPackages:

module.exports = {
    experimental: { 
      appDir: true,
      serverComponentsExternalPackages: ['nodejs-pptx']
    },
    ```