Home > Blockchain >  Error: [BABEL]: Cannot find module './built-in-definitions' in react-native-builder-bob
Error: [BABEL]: Cannot find module './built-in-definitions' in react-native-builder-bob

Time:09-28

when I run the command to build the react-native library:

yarn prepare

show error:

yarn run v1.22.19
$ bob build
ℹ Building target commonjs
ℹ Cleaning up previous build at lib/commonjs
ℹ Compiling 1 files in src with babel
bob build

build files for publishing

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Error: [BABEL]: Cannot find module './built-in-definitions'
Require stack:
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/preset-env/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/module-types.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/configuration.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/utils/compile.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/targets/commonjs.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/index.js
- /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/bin/bob (While processing: /Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/preset-env/lib/index.js)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js:8:27)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/preset-env/lib/index.js:32:34)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/babel-plugin-polyfill-corejs2/lib/index.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/preset-env/lib/index.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/module-types.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/configuration.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/config/files/index.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/@babel/core/lib/index.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/utils/compile.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/targets/commonjs.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/lib/index.js',
    '/Users/ibrahimtahayna/Desktop/react-native-awesome-library/node_modules/react-native-builder-bob/bin/bob'
  ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

why did this error happen? what should I do to fix this problem? I have already tried to remove node-module and yarn.lock. Also when create new project still happening and I try to update react-native-builder-bob.

CodePudding user response:

Did you follow the 'Automatic configuration' or 'Manual configuration' steps as described in the documentation? https://github.com/callstack/react-native-builder-bob#automatic-configuration

It seems like Babel is not configured correctly. It can not find the built-in-definitions.ts file from the babel-polyfills package, which can be found here. https://github.com/babel/babel-polyfills/tree/main/packages/babel-plugin-polyfill-corejs2/src

I think Babel will be set-up correctly after finishing the configuration steps.

Edit: Or did you configure your package using the commonjs build-target during setup? If you want to build a react-native package you should choose the module option. commonjs is used for Node environments, and React-native uses Metro.

  • Related