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.

Unable to get babel-plugin-import to work when scripts are compiled from typescript (Android)

See original GitHub issue

Version

1.4.2

Environment

react-native

Reproduction link

https://github.com/stonecold123/antd-mobile-test-ts

Steps to reproduce

$ git clone https://github.com/stonecold123/antd-mobile-test-ts $ npm install $ npm start $ react-native run-android

What is expected?

I’ve made two examples for android only, one written in raw js (run fine), and one written in typescript (not working): https://github.com/stonecold123/antd-mobile-test-js https://github.com/stonecold123/antd-mobile-test-ts

I was expecting the typescript example to work perfectly without the console.error “Must use babel-plugin-import…” and render successfully like the first one which is written in JS. Both examples use the latest react native and react version.

What is actually happening?

Can you please try this example: https://github.com/stonecold123/antd-mobile-test-ts

I’m still getting the “Must use babel-import…” error even though the .babelrc file has updated to :

{
  "presets": ["react-native"],
  "plugins": [["import", { "libraryName": "antd-mobile" }]]
}

I suspect there’s an issue related to babel-plugin-import when the ts example is compiled back into raw javascript. I have spent hours on it but still can’t find a solution.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cncoldercommented, Jul 13, 2017

@stonecold123 Change your tsconfig.json tell tsc compile to es2015. babel-plugin-import only understand import style code.

{
    "compilerOptions": {
        "module": "es2015"
    }
}

babel-plugin-import will transform import { Button } from 'antd-mobile'; <Button /> into var _button = require('antd-mobile/lib/button'); <_button />

0reactions
cncoldercommented, Jul 13, 2017

@stonecold123 Change your tsconfig.json again

{
    "compilerOptions": {
        "module": "es2015",
        "allowSyntheticDefaultImports": true
    }
}

Then write import URIJS from 'urijs' in your .ts file.

import React, { Component } from 'react'

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'react-native-paper/babel' when ...
when trying to generate APK on windows system getting this error. ... Failed at the react-native-paper@3.0.0-alpha.4 prepare script. npm ERR ...
Read more >
Can't compile typescript from npm scripts
To initialize your project use tsc --init . Then just modify options in compilerOptions in your tsconfig.json . If you are done, compile...
Read more >
babel/plugin-transform-typescript
Replace the function used when compiling JSX fragment expressions. This is so that we know that the import is not a type import,...
Read more >
Common TypeScript module problems and how to solve ...
Solution 1: Locate the correct directory. When we use this configuration, TypeScript compiler “jumps” up a directory from the src directory and ...
Read more >
error ts2307: cannot find module or its corresponding type ...
I am setting up a NodeJS + Mysql + Typescript + Docker app, but have a problem when I try to include the...
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