Skip to content
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

[Bug]: "Cannot find module 'next/dist/server/base-server'" with plugin 4.2.4 and Next 11.x #1198

Closed
1 of 2 tasks
eladroz opened this issue Feb 7, 2022 · 2 comments · Fixed by #1199
Closed
1 of 2 tasks
Labels
type: bug code to address defects in shipped code

Comments

@eladroz
Copy link
Contributor

eladroz commented Feb 7, 2022

Summary

I have a Next.js 11 project (on current latest 11.1.4), and used the plugin thus far with no errors in the Netlify build log.

After bumping the plugin version to latest 4.2.4, I see the following in the build log:

10:31:04 AM: ────────────────────────────────────────────────────────────────
10:31:04 AM: 3. @netlify/plugin-nextjs (onBuild event)
10:31:04 AM: ────────────────────────────────────────────────────────────────
10:31:04 AM: ​
10:31:05 AM: Error: Cannot find module 'next/dist/server/base-server'
10:31:05 AM: Require stack:
10:31:05 AM: - /opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/utils.js
10:31:05 AM: - /opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/files.js
10:31:05 AM: - /opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/index.js
10:31:05 AM: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
10:31:05 AM: at Function.resolve (internal/modules/cjs/helpers.js:107:19)
10:31:05 AM: at findModuleFromBase (/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/utils.js:125:40)
10:31:05 AM: at getServerFile (/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/files.js:257:43)
10:31:05 AM: at patchNextFiles (/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/files.js:260:24)
10:31:05 AM: at onBuild (/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/index.js:47:42)
10:31:05 AM: at async Object.run (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/run.js:21:3)
10:31:05 AM: at async handleEvent (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/child/main.js:41:38)
10:31:05 AM: at async process. (file:///opt/buildhome/node-deps/node_modules/@netlify/build/src/plugins/ipc.js:112:16) {
10:31:05 AM: code: 'MODULE_NOT_FOUND',
10:31:05 AM: requireStack: [
10:31:05 AM: '/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/utils.js',
10:31:05 AM: '/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/helpers/files.js',
10:31:05 AM: '/opt/build/repo/node_modules/@netlify/plugin-nextjs/lib/index.js'
10:31:05 AM: ]
10:31:05 AM: }
10:31:05 AM: Patching /opt/build/repo/node_modules/next/dist/server/next-server.js
10:31:05 AM: Done
...

The build moves on, supposedly normally - so I don't know if this is a truly recoverable error or is gonna impact something.

Steps to reproduce

  1. Create a Next.js 11 project
  2. Install the plugin per instructions
  3. Deploy in Netlify and watch the logs

Note: my test projects were created with Stackbit, but it's a pretty basic Next project.

A link to a reproduction repository

https://github.com/eladroz/adorable-moon-0d4c4

Plugin version

4.2.4

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?

No response

Your netlify.toml file

netlify.toml
[build]
command = "npm run build"
publish = ".next"
functions = ".netlify/functions"

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

Your public/_redirects file

N/A

Your next.config.js file

next.config.js
const sourcebit = require('sourcebit');
const sourcebitConfig = require('./sourcebit.js');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
    enabled: process.env.ANALYZE === 'true'
});

sourcebit.fetch(sourcebitConfig);

module.exports = withBundleAnalyzer({
    trailingSlash: true,
    devIndicators: {
        autoPrerender: false
    },
    eslint: {
        // Allow production builds to successfully complete even if your project has ESLint errors.
        ignoreDuringBuilds: true
    },
    webpack: (config, { dev }) => {
        // Tell webpack to ignore watching content files in the content folder.
        // Otherwise webpack recompiles the app and refreshes the whole page.
        // Instead, the src/pages/[...slug].js uses the "withRemoteDataUpdates"
        // function to update the content on the page without refreshing the
        // whole page
        config.watchOptions.ignored.push('/content/');
        if (dev) {
            // enable tree shaking for development mode, on production it is on by default
            config.optimization.usedExports = true;
        }

        return config;
    }
});

Builds logs (or link to your logs)

https://app.netlify.com/sites/adorable-moon-0d4c4/deploys/6200d88e0a1dbd4b3e186e54

Function logs

N/A

.next JSON files

build-manifest.json
{
  "polyfillFiles": [
    "static/chunks/polyfills-a40ef1678bae11e696dba45124eadd70.js"
  ],
  "devFiles": [],
  "ampDevFiles": [],
  "lowPriorityFiles": [
    "static/huPZfmPtWLl48td8GF4Dd/_buildManifest.js",
    "static/huPZfmPtWLl48td8GF4Dd/_ssgManifest.js"
  ],
  "pages": {
    "/[[...slug]]": [
      "static/chunks/webpack-a4e219bd61a54b3ed948.js",
      "static/chunks/framework-717d42ae9e172961f2a5.js",
      "static/chunks/main-ad8739466991e234b2db.js",
      "static/chunks/96-e35e4da1048a72f6a7f5.js",
      "static/chunks/pages/[[...slug]]-ce4664484f3a27be9fd7.js"
    ],
    "/_app": [
      "static/chunks/webpack-a4e219bd61a54b3ed948.js",
      "static/chunks/framework-717d42ae9e172961f2a5.js",
      "static/chunks/main-ad8739466991e234b2db.js",
      "static/css/748618296eb9bf29c4e9.css",
      "static/chunks/pages/_app-5a038bdee4f93e130014.js"
    ],
    "/_error": [
      "static/chunks/webpack-a4e219bd61a54b3ed948.js",
      "static/chunks/framework-717d42ae9e172961f2a5.js",
      "static/chunks/main-ad8739466991e234b2db.js",
      "static/chunks/pages/_error-737a04e9a0da63c9d162.js"
    ]
  },
  "ampFirstPages": []
}
export-marker.json
{"version":1,"hasExportPathMap":false,"exportTrailingSlash":true,"isNextImageImported":false}
images-manifest.json
{"version":1,"images":{"deviceSizes":[640,750,828,1080,1200,1920,2048,3840],"imageSizes":[16,32,48,64,96,128,256,384],"path":"/_next/image","loader":"default","domains":[],"disableStaticImages":false,"minimumCacheTTL":60,"sizes":[640,750,828,1080,1200,1920,2048,3840,16,32,48,64,96,128,256,384]}}
prerender-manifest.json
{"version":3,"routes":{"/blog":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog.json"},"/blog/page/2":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/page/2.json"},"/blog/post-eight":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-eight.json"},"/blog/post-eleven":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-eleven.json"},"/blog/post-five":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-five.json"},"/blog/post-four":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-four.json"},"/blog/post-nine":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-nine.json"},"/blog/post-one":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-one.json"},"/blog/post-seven":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-seven.json"},"/blog/post-six":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-six.json"},"/blog/post-ten":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-ten.json"},"/blog/post-three":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-three.json"},"/blog/post-twelve":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-twelve.json"},"/blog/post-two":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/blog/post-two.json"},"/careers":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/careers.json"},"/faq":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/faq.json"},"/":{"initialRevalidateSeconds":false,"srcRoute":"/[[...slug]]","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/index.json"}},"dynamicRoutes":{"/[[...slug]]":{"routeRegex":"^(?:/(.+?))?(?:/)?$","dataRoute":"/_next/data/huPZfmPtWLl48td8GF4Dd/[[...slug]].json","fallback":false,"dataRouteRegex":"^/_next/data/huPZfmPtWLl48td8GF4Dd(?:/(.+?))?\\.json$"}},"notFoundRoutes":[],"preview":{"previewModeId":"da0233e1ded96fc4ea850669f4671cf7","previewModeSigningKey":"919aeb68556f0d458aef7a3be15489df1cad1539d446f66ea8f3d9ef0a530d60","previewModeEncryptionKey":"d2dce27b97d64e190e61983019d6335c73d9cfa3453f8959e5ae45d2e1916924"}}
react-loadable-manifest.json
{
  "../components/components-registry.ts -> ./layouts/PageLayout": {
    "id": 7653,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/653.a93d54ad39e3e6b90fef.js"
    ]
  },
  "../components/components-registry.ts -> ./layouts/PostFeedCategoryLayout": {
    "id": 6212,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/212.8fcaa4dd3d33a6c26842.js"
    ]
  },
  "../components/components-registry.ts -> ./layouts/PostFeedLayout": {
    "id": 5379,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/379.7b0d142eae15c9fc5bb7.js"
    ]
  },
  "../components/components-registry.ts -> ./layouts/PostLayout": {
    "id": 6170,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/170.fd725ac367f71837e37a.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock": {
    "id": 7364,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/32.e5075e0b7373369f3d5c.js",
      "static/chunks/364.1ed03e496b1a807a685c.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock/CheckboxFormControl": {
    "id": 5805,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/805.f84c1af0376be1b50fe6.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock/EmailFormControl": {
    "id": 4125,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/125.eda5206775cc6f660c16.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock/SelectFormControl": {
    "id": 2081,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/81.6799ac4744e48115a7e7.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock/TextFormControl": {
    "id": 6440,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/440.805636a2af096fb4ebe4.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/FormBlock/TextareaFormControl": {
    "id": 2137,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/137.42509d6f6524c6ad281a.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/ImageBlock": {
    "id": 9495,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js"
    ]
  },
  "../components/components-registry.ts -> ./molecules/VideoBlock": {
    "id": 3395,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/395.e623324544c53fa350c7.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/ContactSection": {
    "id": 1012,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/32.e5075e0b7373369f3d5c.js",
      "static/chunks/12.97ad811b181ec0e2e7b4.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/CtaSection": {
    "id": 4100,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/100.14f11bc67b3850ba312d.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FaqSection": {
    "id": 2973,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/973.065578220fd5749a600f.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FeatureHighlightSection": {
    "id": 5617,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/617.6ba39dc9be9f10b594f6.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FeaturedItemsSection": {
    "id": 8819,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/819.f8447e7eddb3d8b7d720.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FeaturedItemsSection/FeaturedItem": {
    "id": 4395,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/817.d69978089c2b5459c670.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FeaturedPeopleSection": {
    "id": 8291,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/291.b6286a089cca17d4b12a.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/FeaturedPostsSection": {
    "id": 2469,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/469.5414d9c22415d31067f5.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/HeroSection": {
    "id": 7778,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/778.caba21acffdedb94e6a9.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/JobsSection": {
    "id": 5067,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/67.6a5df80c481ab914b277.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/MediaGallerySection": {
    "id": 4835,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/835.d905cb3c91a590aed7ec.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/PostFeedSection": {
    "id": 5600,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/QuoteSection": {
    "id": 7407,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/407.4995a65b8367d59a6c54.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/RecentPostsSection": {
    "id": 3419,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/419.9c9163812411648c00ec.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/TestimonialsSection": {
    "id": 9403,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/403.c334d2c4cb1032cbf4ef.js"
    ]
  },
  "../components/components-registry.ts -> ./sections/TextSection": {
    "id": 7864,
    "files": [
      "static/chunks/commons.8b56289c3d94c0e7ca00.js",
      "static/chunks/864.ff6db690936087ae4030.js"
    ]
  }
}
required-server-files.json
{"version":1,"config":{"env":{},"webpackDevMiddleware":null,"eslint":{"ignoreDuringBuilds":true},"typescript":{"ignoreBuildErrors":false},"distDir":".next","cleanDistDir":true,"assetPrefix":"","configOrigin":"next.config.js","useFileSystemPublicRoutes":true,"generateEtags":true,"pageExtensions":["tsx","ts","jsx","js"],"target":"server","poweredByHeader":true,"compress":false,"analyticsId":"","images":{"deviceSizes":[640,750,828,1080,1200,1920,2048,3840],"imageSizes":[16,32,48,64,96,128,256,384],"path":"/_next/image","loader":"default","domains":[],"disableStaticImages":false,"minimumCacheTTL":60},"devIndicators":{"buildActivity":true,"autoPrerender":false},"onDemandEntries":{"maxInactiveAge":60000,"pagesBufferLength":2},"amp":{"canonicalBase":""},"basePath":"","sassOptions":{},"trailingSlash":true,"i18n":null,"productionBrowserSourceMaps":false,"optimizeFonts":true,"excludeDefaultMomentLocales":true,"serverRuntimeConfig":{},"publicRuntimeConfig":{},"reactStrictMode":false,"httpAgentOptions":{"keepAlive":true},"experimental":{"swcLoader":false,"swcMinify":false,"cpus":7,"sharedPool":false,"plugins":false,"profiling":false,"isrFlushToDisk":true,"workerThreads":false,"pageEnv":false,"optimizeImages":false,"optimizeCss":false,"scrollRestoration":false,"stats":false,"externalDir":false,"reactRoot":false,"disableOptimizedLoading":false,"gzipSize":true,"craCompat":false,"esmExternals":false,"staticPageGenerationTimeout":60,"isrMemoryCacheSize":52428800,"nftTracing":false,"concurrentFeatures":false},"future":{"strictPostcssConfiguration":false}},"appDir":"/Users/eladrosenheim/Documents/GitHub/adorable-moon-0d4c4","files":[".next/routes-manifest.json",".next/server/pages-manifest.json",".next/build-manifest.json",".next/prerender-manifest.json",".next/react-loadable-manifest.json",".next/server/font-manifest.json",".next/BUILD_ID"],"ignore":["node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*"]}
routes-manifest.json
{"version":3,"pages404":true,"basePath":"","redirects":[{"source":"/:file((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+)/","destination":"/:file","internal":true,"statusCode":308,"regex":"^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+))/$"},{"source":"/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)","destination":"/:notfile/","internal":true,"statusCode":308,"regex":"^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+))$"}],"headers":[],"dynamicRoutes":[{"page":"/[[...slug]]","regex":"^(?:/(.+?))?(?:/)?$","routeKeys":{"slug":"slug"},"namedRegex":"^(?:/(?<slug>.+?))?(?:/)?$"}],"dataRoutes":[{"page":"/[[...slug]]","routeKeys":{"slug":"slug"},"dataRouteRegex":"^/_next/data/huPZfmPtWLl48td8GF4Dd(?:/(.+?))?\\.json$","namedDataRouteRegex":"^/_next/data/huPZfmPtWLl48td8GF4Dd(?:/(?<slug>.+?))?\\.json$"}],"rewrites":[]}
@eladroz eladroz added the type: bug code to address defects in shipped code label Feb 7, 2022
@ascorbic
Copy link
Contributor

ascorbic commented Feb 7, 2022

Ah, thanks for the report. Yes, this is fine as it is just iterating through various files until it finds the correct one. The next line shows it has found next/dist/server/next-serve instead. That said, it shouldn't be logging this confusing error, so I'll make sure that's removed.

@eladroz
Copy link
Contributor Author

eladroz commented Feb 8, 2022

Thanks for fixing this so quickly, and awesome king rodent in the #1199 PR ;-)

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