Skip to content

[Bug]: getPageResolver generating incorrect paths on Windows #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
rshackleton opened this issue Dec 8, 2021 · 18 comments · Fixed by #948
Closed
2 tasks done

[Bug]: getPageResolver generating incorrect paths on Windows #941

rshackleton opened this issue Dec 8, 2021 · 18 comments · Fixed by #948
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@rshackleton
Copy link

rshackleton commented Dec 8, 2021

Steps to reproduce

When using the latest RC version of the plugin all SSR pages in Next.js are failing to find the styled-components dependency imported in _document.ts.

This is happening with and without the esbuild function bundle option. The repo is a private repo so I cannot share this currently, I can see about trying to put together a reproduction repo but that will take some time.

A link to a reproduction repository

No response

Plugin version

^4.0.0-rc.1

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Windows

Your netlify.toml file

`netlify.toml`
[build]
command = "yarn build"
publish = ".next"

[functions]
node_bundler = "esbuild"

[[plugins]]
package = "@netlify/plugin-nextjs"

Relevant log output (or link to your logs)

Build logs
1:45:45 PM: f3de4f18 ERROR  Error: Cannot find module 'styled-components'
Require stack:
- /var/task/packages/web/.next/server/pages/_document.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/load-components.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/packages/web/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js
- /var/task/packages/web/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js
- /var/task/___netlify-odb-handler.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.7518 (/var/task/packages/web/.next/server/pages/_document.js:115:18)
    at __webpack_require__ (/var/task/packages/web/.next/server/webpack-runtime.js:25:42)
    at Object.8684 (/var/task/packages/web/.next/server/pages/_document.js:16:75)
    at __webpack_require__ (/var/task/packages/web/.next/server/webpack-runtime.js:25:42)
    at __webpack_exec__ (/var/task/packages/web/.next/server/pages/_document.js:125:39)
    at /var/task/packages/web/.next/server/pages/_document.js:126:70 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/packages/web/.next/server/pages/_document.js',
    '/var/task/node_modules/next/dist/server/require.js',
    '/var/task/node_modules/next/dist/server/load-components.js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/packages/web/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js',
    '/var/task/packages/web/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js',
    '/var/task/___netlify-odb-handler.js',
    '/var/runtime/UserFunction.js',
    '/var/runtime/index.js'
  ]
}
@rshackleton rshackleton added the type: bug code to address defects in shipped code label Dec 8, 2021
@ascorbic
Copy link
Contributor

ascorbic commented Dec 8, 2021

Hey. Thanks for the report. I think I am going to need a repro from you, because I've failed to reproduce it myself. See #943 and the deploy preview

@rshackleton
Copy link
Author

I'm thinking it might be due to it being in a monorepo. It is a Sanity project so we have the following structure:

package.json
packages/
  studio/
    package.json
  web/
    package.json

Perhaps the Netlify function isn't able to bundle the packages from the monorepo properly? I should have some time free tomorrow to try and investigate and put together a reproduction. 🤞

@ascorbic
Copy link
Contributor

ascorbic commented Dec 9, 2021

Thank you. It shouldn't be a problem with it being a monorepo, as we have several monorepo test sites, but it may still be related. A repro would be useful. It would also be helpful if you could run netlify build locally, and share the content of .netlify/functions-internal/___netlify-odb-handler/pages.js

@rshackleton
Copy link
Author

The pages.js file from running the netlify build locally. Not sure if this is what is generated on the server though, can't see how it could possible resolve from here if it was.

// This file is purely to allow nft to know about these pages. It should be temporary.
exports.resolvePages = () => {
    try {
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/404.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/500.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/[slug].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/_app.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/_document.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/_error.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/formium/[formid].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/indexers/products-full.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/indexers/products-webhook.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/indexers/site-full.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/indexers/site-webhook.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/media.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/api/vacancies.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/applications/[application].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/applications/[application]/[subapplication].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/index.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/media.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/media/[slug].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/products.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/products/[category].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/products/[category]/[subcategory].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/products/[category]/[subcategory]/[product].js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/search-results.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/sitemap.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/sitemap.xml.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/vacancies.js')
        require.resolve('../../../C:\Projects\ClientName\packages\web\.next/server/pages/vacancies/[slug].js')
    } catch {}
}

@rshackleton
Copy link
Author

We're using Azure DevOps for our CI process and decided to try running the same build/release process on a Unix agent and it appears to have resolved the issue for us. There must be something going awry on Windows agents specifically.

@ascorbic
Copy link
Contributor

ascorbic commented Dec 9, 2021

Oh yes that does look like it! Thanks for the report. I will rename this issue and prioritise a fix.

@ascorbic ascorbic changed the title [Bug]: Netlify function cannot find dependency for Next.js SSR page [Bug]: getPageResolver generating incorrect paths on Windows Dec 9, 2021
@ascorbic ascorbic self-assigned this Dec 9, 2021
@ascorbic
Copy link
Contributor

ascorbic commented Dec 9, 2021

Can you confirm which version of Node is being used in the build? It would be useful if you could share the build logs too. We run integration tests on Windows which include snapshots of the pages.js file, so it does seem to generate the correct ones there at least.

@rshackleton
Copy link
Author

Sorry just checked back in on this, the node version would have been 14.16.0. To be honest it should have been updated to use the latest LTS but that was how the release was setup when we last ran it on the Windows agent.

I can share the log directly if you're able to provide a contact email or similar. Would prefer not to post the entire log on here just in case.

@ascorbic
Copy link
Contributor

ascorbic commented Dec 9, 2021

I have a probable solution. I'll see if I can get that in a release today.

@kodiakhq kodiakhq bot closed this as completed in #948 Dec 10, 2021
@ascorbic
Copy link
Contributor

This should be fixed in rc.2

@rshackleton
Copy link
Author

@ascorbic I've updated to rc.2 and ran the release process on the Windows agent and we're getting the entire site timing out with this error now.

{"errorMessage":"2021-12-10T14:37:39.530Z 43f7001e-3228-4aa8-ad43-fa9a3d2abb6d Task timed out after 10.01 seconds"}

image

@ascorbic
Copy link
Contributor

@rshackleton oh dear. Can you share the pages.js file again? Does it still work with the linux agent? I have been thinking about it, and realise that there are svereal things that could cause problems deploying from a Windows agent, because it's building functions that are deployed to Lambda functions running on Linux. I would liek to get builds working properly on Windows, but this is somehting to bear in mind.

@rshackleton
Copy link
Author

rshackleton commented Dec 10, 2021

We're ok using the hosted Ubuntu agents for now, and we're looking at setting up our own dedicated Ubuntu agent to run alongside our Windows agents so that should be fine for us in the long run.

I'll try and get the pages.js file and logs to you but we're currently trying to fix the stack overflow issue that has come up with installing the latest Netlify CLI. 😫

@ascorbic
Copy link
Contributor

Would that be this issue?

@rshackleton
Copy link
Author

rshackleton commented Dec 10, 2021

Yep, we were using the CLI via a global install so we're updating the CI to use it via a dev dependency. That is fixed now and I think the timeout issue might actually be due to me enabling ISR earlier on - I wasn't able to properly check that was working properly because of the release issues. 🤦‍♂️

Just undoing those changes so we can verify it is working on the Ubuntu agent again, then I can try it on the Windows agent and see how it works out.

It has been a bit of a day. 😅

@rshackleton
Copy link
Author

Ok, so we're back up and running. Tested the build on rc.2 on both Ubuntu and Windows agent and both are working great now, no more dependency issue even on the Windows agent!

@ascorbic
Copy link
Contributor

Oh wow, that's great news! Thanks so much for your help in tracking this down.

@rshackleton
Copy link
Author

No worries, cheers for getting a fix out so promptly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants