react-native-device-info: Syntax error: Unexpected token in src/index.ts

During compilation i get this error

error: bundling failed: SyntaxError: .../node_modules/react-native-device-info/src/index.ts: Unexpected token (12:12)

I guess this is maybe because I am not using TypeScript in my project. Should I? I tried to remove the field react-native from the package.json of your module - and this error gone. Could you please recommend how to fix this?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27

Most upvoted comments

I have the same error today after upgrading to 8.0.1 from 2.x.

I had to remove Line 5react-native": "src/index.ts", from node_modules/react-native-device-info/package.json to make it work.

I had a similar issue. I upgraded it from 2.1.2 to the 8.4.4 version and my react-native version is (0.59.10). I don’t use typescript in my project. Having the following dev dependencies fixed this issue for me.

“devDependencies”: { “@babel/core”: “^7.9.0”, “@babel/runtime”: “^7.9.2”, //other dev dependencies }

Found this solution from the accepted answer from this, https://stackoverflow.com/questions/62270438/react-native-error-bundling-failed-syntaxerror-react-native-projects-appone-n

I’m not sure why this is closed as I don’t see a fix or workaround and the issue definitely exists for some. I upgraded to v8.0.2, but I also got the same error on v8.0.1 too. I downgraded to v7.3.1 and seems to work ok for me. BTW, I am currently running on the following:

react: 16.9.0 react-native: 0.61.5

The app is never able to start after upgrading to v8.0.2. I am not using typescript in my app. Unfortunately, I do not have a project on GitHub that is publicly available. I am planning to upgrade to the latest react native soon, so hopefully that resolves it.

I have the same error today after upgrading to 8.0.1 from 2.x.

I had to remove Line 5react-native": "src/index.ts", from node_modules/react-native-device-info/package.json to make it work.

Thanks it worked

Wow, that was unexpectedly pretty impolite answer. The bug we are talking about was introduced by this commit: https://github.com/react-native-device-info/react-native-device-info/commit/8af015f832fd5a4125d4b97979b86555fb710e64#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80 The thing is all about importing and exporting types. Downgrading the module version to 8.0.0 fixes the issue. It is advisable to pay more attention to what other participants of open-source community report, without unneccesary requirements to post anything on github in order to prove that your module actually has bugs. As for “gold standard” - don’t you think that such a breaking change deserves more that a minor version upgrade? That’s a ritoric question by the way. Good luck!

If you can reproduce this failure with the example, we can investigate, but it is likely something project specific about how you are consuming the module, perhaps in some nonstandard way like not from npmjs.com ?

I installed the module in usual way using npm install --save react-native-device-info. For some reason, when "react-native": "src/index.ts" is present in node_modules/react-native-device-info/package.json - the issue is happening, builder tries to load src/index.ts and fails. Without this field everything works well. Manually removing a field from package.json is not a sustainable solution…