question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module '@babel/plugin-transform-shorthand-properties'

See original GitHub issue

Library works fine in 1.10.3. Fails on 2.1.0.

  ● Test suite failed to run

  /node_modules/react-native-gesture-handler/lib/commonjs/handlers/gestures/GestureDetector.js: Cannot find module '@babel/plugin-transform-shorthand-properties'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

70reactions
UNIDY2002commented, Dec 22, 2021

I think I’ve figured out the root cause of this issue (at least in my case).

The problem lies with the inconsistency in the versions of babel-related packages in yarn.lock.

To be specific, metro-react-native-babel-transformer requires @babel/core@^7.14.0, but my project package.json requires @babel/core@7.16.5. Just like the following require stack,

error node_modules/react-native-gesture-handler/src/handlers/gestures/GestureDetector.tsx: /home/unidy/repos/THUInfoAdmin/node_modules/react-native-gesture-handler/src/handlers/gestures/GestureDetector.tsx: Cannot find module '@babel/plugin-transform-shorthand-properties'
Require stack:
- /home/unidy/repos/THUInfoAdmin/node_modules/@babel/core/lib/config/files/plugins.js      <-- @babel/core@7.16.5
- /home/unidy/repos/THUInfoAdmin/node_modules/@babel/core/lib/config/files/index.js        <-- @babel/core@7.16.5
- /home/unidy/repos/THUInfoAdmin/node_modules/@babel/core/lib/index.js                     <-- @babel/core@7.16.5
- /home/unidy/repos/THUInfoAdmin/node_modules/react-native-reanimated/plugin.js
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/config/files/module-types.js         <-- @babel/core@^7.14.0
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/config/files/configuration.js        <-- @babel/core@^7.14.0
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/config/files/index.js                <-- @babel/core@^7.14.0
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/index.js                             <-- @babel/core@^7.14.0
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-react-native-babel-transformer/src/index.js
- /home/unidy/repos/THUInfoAdmin/node_modules/metro-transform-worker/src/index.js
- /home/unidy/repos/THUInfoAdmin/node_modules/metro/src/DeltaBundler/Worker.js
- /home/unidy/repos/THUInfoAdmin/node_modules/jest-worker/build/workers/processChild.js.

So it might bring confusion to babel, causing it to complain about being unable to find @babel/plugin-transform-shorthand-properties.


Simply downgrading @babel/core to ^7.14.0 might not solve the problem, as things get complicated due to the fact that react-native-codegen indirectly requires @babel/core@^7.1.6. Fortunately, there are some workarounds:

  • add both @babel/preset-env and @babel/preset-typescript to the dependencies (or devDependencies) list of the project package.json file
  • or simply delete yarn.lock and regenerate it

Finally, if there have to be someone responsible for the issue, at least the responsibility does not lies with react-native-gesture-handler. Perhaps react-native can do something to handle this issue.

11reactions
UNIDY2002commented, Dec 19, 2021

It turns out that I have to install both @babel/preset-env and @babel/preset-typescript as dependencies (or devDependencies) to make things work in my project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@babel/plugin-transform-shorthand-properties - npm
Compile ES2015 shorthand properties to ES5. ... Start using @babel/plugin-transform-shorthand-properties in your project by running `npm i ...
Read more >
babel/plugin-transform-shorthand-properties
NOTE: This plugin is included in @babel/preset-env ... npm install --save-dev @babel/plugin-transform-shorthand-properties.
Read more >
How do I install node module @babel/plugin-transform-class ...
Notice the name change from "plugin-transform-class-properties" ... Searched for node-sass for babel 7.11.4 Found the fix here.
Read more >
@babel/plugin-transform-shorthand-properties | Yarn - Yarn
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
babel/plugin-transform-shorthand-properties - npm package
@babel/plugin-transform-shorthand-properties · Compile ES2015 shorthand properties to ES5 For more information about how to use this package see README · Security.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found