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

Couldn't find preset "./.babelrc.js" relative to directory "/node_modules/react-virtualized" #1112

Closed
razius opened this issue May 17, 2018 · 21 comments

Comments

@razius
Copy link

razius commented May 17, 2018

I get the following error while trying to compile with the latest version (9.19.0).

Module build failed: Error: Couldn't find preset "./.babelrc.js" relative to directory "/unisport/storefront/node_modules/react-virtualized"
    at /unisport/storefront/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/unisport/storefront/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/unisport/storefront/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/unisport/storefront/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/unisport/storefront/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/unisport/storefront/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/unisport/storefront/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/unisport/storefront/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/unisport/storefront/node_modules/babel-loader/lib/index.js:50:20)
    at Object.module.exports (/unisport/storefront/node_modules/babel-loader/lib/index.js:173:20)
 @ ./node_modules/react-virtualized-select/dist/commonjs/VirtualizedSelect/VirtualizedSelect.js 41:17-69
 @ ./node_modules/react-virtualized-select/dist/commonjs/VirtualizedSelect/index.js
 @ ./node_modules/react-virtualized-select/dist/commonjs/index.js
@TrySound
Copy link
Contributor

@razius

{
  test: /\.js$/,
  exclude: /node_modules/, // add this line
  loader: 'babel-loader'
}

@razius
Copy link
Author

razius commented May 17, 2018

@TrySound , thank you. I didn't know about this.

Feel silly now :)

@razius razius closed this as completed May 17, 2018
@GlebDolzhikov
Copy link

I have the same issue during the running tests in jest. Any suggestions?

@TrySound
Copy link
Contributor

@GlebDolzhikov same answer. Do not transpile node_modules

@logeshpaul
Copy link

@TrySound I had the same issue, adding that line resolved the issue. Thanks for posting 👍

@GlebDolzhikov
Copy link

But as i understand it's a part of webpack config? My test environment doesn't use webpack, i try to add transformIgnorePatterns to jest.config - in vain

@TrySound
Copy link
Contributor

TrySound commented May 30, 2018

Just skip this option.
transformIgnorePatterns [array]
Default: ["/node_modules/"]

@GlebDolzhikov
Copy link

doesn't work for me, finish it up by fixed "react-virtualized": "9.18.5",

@TrySound
Copy link
Contributor

@GlebDolzhikov Could you create reproducing repository?

@GlebDolzhikov
Copy link

Will try when I have some spare time;)

@geminiyellow
Copy link

same error.

and i set include src only.

ref: #1112 (comment)

@TrySound
Copy link
Contributor

@geminiyellow Show config

@anlesk
Copy link

anlesk commented Jul 5, 2018

Faced with the same error. The proposed solution for excluding node_modules folder is not working for me - I have several dependencies that are not being transpiled for non-es6 usage.

So I ended up having the configuration like this:

{
  test: /\.js$/,
  exclude: [
    /node_modules[\\/]react-virtualized/,
  ],
  loader: 'babel-loader',
}

@zackerydev
Copy link

zackerydev commented Jul 27, 2018

I had this issue while running Jest tests, but it was my fault so I'm leaving it here for anyone else who has the same issue.

I am locked to an earlier version of React (15.x) and thereby an old version of react-virtualized

To shrink our bundle we used the method pointed out here #427 (comment) and imported react-virtualized like:

import { MultiGrid } from 'react-virtualized/dist/es/MultiGrid';

But this caused this error to happen with Jest, once I changed the import to:

import { MultiGrid } from 'react-virtualized/dist/commonjs/MultiGrid';

The problem went away and was being properly transpiled

@TrySound
Copy link
Contributor

@zgriesinger es output will be bundled with less noise in the output bundle. To solve the issue with jest you can use jest mocking

jest.mock('react-virtualized/dist/es/MultiGrid', () =>
  require('react-virtualized/dist/commonjs/MultiGrid')
)

@zackerydev
Copy link

Worked perfectly thanks!

@reginagarkin
Copy link

getting the same error as above:

Error: Couldn't find preset "./.babelrc.js" relative to directory "/Users/myFolder/ui/build/vneraapp/js/vendor/react-virtualized"
    at /Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/Users/myFolder/ui/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at DestroyableTransform._transform (/Users/myFolder/ui/node_modules/gulp-babel/index.js:36:22)
Emitted 'error' event at:
    at DestroyableTransform.onerror (/Users/myFolder/ui/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:558:12)
    at DestroyableTransform.emit (events.js:182:13)
    at DestroyableTransform._transform (/Users/myFolder/ui/node_modules/gulp-babel/index.js:54:9)
    at DestroyableTransform.Transform._read (/Users/myFolder/ui/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Readable.read (/Users/myFolder/ui/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:443:10)
    at flow (/Users/myFolder/ui/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:813:34)
    at DestroyableTransform.<anonymous> (/Users/myFolder/ui/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:683:7)
    at DestroyableTransform.emit (events.js:182:13)
    at onwriteDrain (/Users/myFolder/ui/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_writable.js:300:12)
    at afterWrite (/Users/myFolder/ui/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_writable.js:288:5)

and webpack is setup this way too:

test: /\.jsx?$/,
exclude: /node_modules/,

What's causing this issue?

@AlexMold
Copy link

You can add this option in package.json in root of your project to exclude your libraries like react-virtualized

Example:
"jest": { "setupFiles": [ "./config/jest.setup.js" ], "transformIgnorePatterns": [ "/!node_modules\\/lodash-es/", "/!node_modules\\/react-virtualized/" ] }

@AlexMold
Copy link

This alternative of jest.mock

@IanVS
Copy link
Contributor

IanVS commented Oct 23, 2018

Re: #1112 (comment), is it necessary to mock these in every one of my tests which are failing? Or is there a better way to do this globally?

@adamdicarlo
Copy link

This seems like a bug to me.

Being as react-virtualized ships an es build, and points to it via its package.json module and jsnext:main keys, it should also ship its babelrc.js file.

I'm not sure what use the es build is with the babel config being broken.

The reason it's particularly broken is because react-virtualized's package.json has this stanza:

  "babel": {
    "presets": [
      "./.babelrc.js"
    ]
  },

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

No branches or pull requests