Next.js: All examples failing to build with `Error: Cannot find module './dist/server/build/babel/preset'`

Created on 24 May 2018  路  6Comments  路  Source: vercel/next.js

Examples bug report

Example name

with-react-helmet, using-router, basic-css etc

Describe the bug

Fails to build with bable error:

{ Error: Cannot find module './dist/server/build/babel/preset'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
    at Function.Module._load (internal/modules/cjs/loader.js:497:25)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/a_user/dev/nextbug/next.js/babel.js:1:80)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at requireModule (/Users/a_user/dev/nextbug/next.js/examples/with-react-helmet/node_modules/@babel/core/lib/config/files/plugins.js:142:12)
    at loadPreset (/Users/a_user/dev/nextbug/next.js/examples/with-react-helmet/node_modules/@babel/core/lib/config/files/plugins.js:56:15)
    at createDescriptor (/Users/a_user/dev/nextbug/next.js/examples/with-react-helmet/node_modules/@babel/core/lib/config/config-descriptors.js:152:21)
    at /Users/a_user/dev/nextbug/next.js/examples/with-react-helmet/node_modules/@babel/core/lib/config/config-descriptors.js:104:12 code: 'MODULE_NOT_FOUND' }

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

git clone [email protected]:zeit/next.js.git && cd ./next.js/examples/basic-css && yarn install && yarn run build

Expected behavior

Should build without error

System information

  • OS: osx
  • Version of Next.js: 6.0.3

Additional context

I think it's something to do with babel dependencies
Probably related to #4467

Most helpful comment

If you git clone you have to build Next.js (yarn build in the main directory) first before executing any of the examples, since the built babel preset is used. This is why none of the instructions for the examples mention cloning the repository 馃憤 Also cloning the repository for 1 out of 100+ examples takes a lot of time usually, that's why we favor downloading / npx init / yarn create

All 6 comments

If you git clone you have to build Next.js (yarn build in the main directory) first before executing any of the examples, since the built babel preset is used. This is why none of the instructions for the examples mention cloning the repository 馃憤 Also cloning the repository for 1 out of 100+ examples takes a lot of time usually, that's why we favor downloading / npx init / yarn create

There's no indication in the package.json that this is the case - how does that actually work? (Genuinely don't understand how that is happening)

Babel looks recursively up the tree for a .babelrc, there is no way to disable this, so we had to add a .babelrc in the examples directory, except that doesn't allow for finding the respective next/babel for the example. So you have to manually build next.js and then the next/babel preset is available.

Ahh, thanks!

So does it mean that in our own app, we need to include this .babelrc file too?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timneutkens picture timneutkens  路  3Comments

havefive picture havefive  路  3Comments

ghost picture ghost  路  3Comments

rauchg picture rauchg  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments