Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Resvg in next: using a function from multiple routes breaks the build #45

Closed
udatny opened this issue Aug 20, 2024 · 5 comments
Closed

Comments

@udatny
Copy link

udatny commented Aug 20, 2024

Describe the bug
Once I reference a function using resvg more than once from a route, the next build fails.
Which version of Next.js? 14.2.5
Which version of nextjs-node-loader? 1.1.5

To Reproduce
Steps to reproduce the behavior or even better. Share me a link to repository with reproducable:

Dear amarjanica
I am using your loader to work with resvg in next (14.x). I encountered an issue and isolated it as good as possible. I am stuck there and asking for your support.

The issue is, that once I reference the function using resvg more than once, the build fails.
You can checkout my fork, go to the examples/next-14-resvg folder and reproduce the issue as follows:

all is good up to here.

These two endpoints do actually exactly the same, just listen on a different path. Expectation is, that you get a 200

  • Now, if you run a npm run build, you will encounter the issue I am talking about. In my case, I am on windows, in a git bash, I get a
    Error: Cannot find module './resvgjs.win32-x64-msvc.node'
> Build error occurred
Error: Failed to collect page data for /api/render2d/[slug]

randomly for one of the the api endpoints.

  • To resolve the issue, you can just delete one of the identical api folders (for example “/app/api/renderXd”) and the build will pass afterwards
  • To reestablish the build issue, just copy the remaining api folder and give it another name, the build will fail again.

Since you seem to be familiar with webpack and loading and building I’d be happy if you could have a look into that.
Thanks.

@amarjanica
Copy link
Member

Hey @udatny, thank you for detailed reporting of this issue! I really appreciate your contribution. Unfortunately, I’m a bit swamped at the moment, but I’ll try to make some time in the next few days to look into this. I’ll keep you updated on the progress.

@aluferraz
Copy link

+1, same issue here

@amarjanica
Copy link
Member

amarjanica commented Aug 30, 2024

Hey @udatny, sorry for being late.
Good thing is that I have the correct environment to reproduce this issue as I work on Windows too recently.
There's a couple of issues and I'm not sure it's all due to nextjs-node-loader.

  • Loader wasn't called at all - I ran the build in debug mode, put a breakpoint and it wasn't until I changed the nextjs webpack configuration, it started to call my loader. I'm not sure why the original regex doesn't work in this case.
 config.module.rules.push({
      test: /.+.node$/ig,
      use: [
        {
          loader: 'nextjs-node-loader',
          options: {
            flags: os.constants.dlopen.RTLD_NOW,
            outputPath: config.output.path
          },
        },
      ],
    });
  • When build process started, correct loader gets called but I get all of these different platforms:
    Is it something you need to configure in your native build configuration?
    It requests all possible platforms.
    In my case it should only require resvgjs.win32-x64-msvc.node which is in the .next/server/app/chunks:
./node_modules/@resvg/resvg-js/js-binding.js
Module not found: Can't resolve './resvgjs.android-arm64.node' in '...\nextjs-node-loader2\examples\next-14-resvg\node_modules\@resvg\resvg-js'
@resvg/resvg-js-android-arm-eabi

@amarjanica
Copy link
Member

This might be related to #48, I'm closing this issue, try the 1.1.8

@udatny
Copy link
Author

udatny commented Oct 15, 2024

thank you very much for taking care of my issue. i tried once with the modified test regex as you proposed: test: /.+.node$/ig,
the results were mixed. while it worked on windows, the build failed on linux.

so i searched further and got this hint here: thx/resvg-js#315 (comment)

and by using this, i dont need any custom loader anymore and it works in all situations (e.g win/linux dev / build).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants