heavysixer / node-pptx

Generate PPTX files on the server-side with JavaScript.
MIT License
162 stars 45 forks source link

Problems calling the library front next.js #124

Open rundro opened 1 year ago

rundro commented 1 year ago

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:

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();
    }
rundro commented 1 year ago

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

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