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

error: pattern matching in instanceof is not supported in -source 8 #2347

Closed
andrei-kopysov opened this issue Jul 12, 2024 · 9 comments · Fixed by #2354
Closed

error: pattern matching in instanceof is not supported in -source 8 #2347

andrei-kopysov opened this issue Jul 12, 2024 · 9 comments · Fixed by #2354
Labels
Missing repro This issue need minimum repro scenario

Comments

@andrei-kopysov
Copy link

Description

Cannot build project with react-native-svg 15.4.0
I am getting this error
> Task :react-native-svg:compileReleaseJavaWithJavac FAILED .../node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/FilterView.java:83: error: pattern matching in instanceof is not supported in -source 8 if (node instanceof FilterPrimitiveView currentFilter) { ^ (use -source 16 or higher to enable pattern matching in instanceof) 1 error

Steps to reproduce

yarn add react-native-svg 15.4.0
build project
project won't compile

Snack or a link to a repository

not needed

SVG version

15.4.0

React Native version

0.71.14

Platforms

macOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

None

Build type

Release app & production bundle

Device

None

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added the Missing repro This issue need minimum repro scenario label Jul 12, 2024
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@bohdanprog
Copy link
Member

bohdanprog commented Jul 15, 2024

@andrei-kopysov Hello,
Could you provide a simple example of how to reproduce that?
Unfortunately, I didn't have that error.
Thank you.

@bohdanprog bohdanprog added the Close when stale This issue is going to be closed when there is no activity for a while label Jul 16, 2024
@thoadao0301
Copy link

I got the same problem with @andrei-kopysov. it ran until I remove node_modules and reinstall. My java version: 19.0.2, gradle version: 7.6.3, react-native-svg: 15.3.0, react-native: 0.70.14

@github-actions github-actions bot removed the Close when stale This issue is going to be closed when there is no activity for a while label Jul 16, 2024
@bohdanprog
Copy link
Member

@thoadao0301 Can you provide an example?

@thoadao0301
Copy link

@bohdanprog I create an example like this
npx react-native init example --version 0.70
yarn add react-native-svg
yarn add react-native-svg-transformer
add declaration.d.js
declare module "*.svg" { import { SvgProps } from "react-native-svg"; const content: React.FC<SvgProps>; export default content; }
modify metro.config.js
`/**

const {getDefaultConfig} = require('metro-config');

module.exports = (async () => {
const {
resolver: {sourceExts, assetExts},
} = await getDefaultConfig();
return {
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
},
};
})();`
and then run yarn android

  • java version: 19.0.2
  • gradle version: 7.5.1
  • "react-native": "0.70.15",
  • "react-native-svg": "^15.4.0",
  • "react-native-svg-transformer": "^1.5.0"
  • running in window
  • android device: samsung galaxy s20

The problem reports:
node_modules\react-native-svg\android\src\main\java\com\horcrux\svg\FilterView.java:83: error: pattern matching in instanceof is not supported in -source 8
if (node instanceof FilterPrimitiveView currentFilter) {
^
(use -source 16 or higher to enable pattern matching in instanceof)

@Geocld
Copy link

Geocld commented Jul 17, 2024

Same issue, version 15.4.0 can not be compiled in Android. Use 15.3.0 working for me.

@thoadao0301
Copy link

Working in version 15.2.0, check your package.json use ~ instead ^ before version

@bohdanprog
Copy link
Member

Hello @thoadao0301 @Geocld @andrei-kopysov,
here is patch react-native-svg+15.4.0.patch
It should fix the problem.

bohdanprog added a commit that referenced this issue Jul 18, 2024
# Summary
Closes #2347
Fixed a problem with building an Android app, pattern matching threw an
error when we tried to build an Android app.

[Repository](https://github.com/bohdanprog/react-native-svg-error-pattern-matching)
to reproduce that error.
## Test Plan
We can easily check that build the app.

### What are the steps to reproduce (after prerequisites)?
build the app without that fix.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| Android |    ✅     |
@StefanoCremona
Copy link

15.3.0 Worked for me too building for Android on Ubuntu:

"react": "18.1.0",
"react-native": "0.70.6",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants