Skip to content

[react native] Namespace not marked type-only declare. #2400

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

Closed
ghost opened this issue Nov 17, 2019 · 8 comments
Closed

[react native] Namespace not marked type-only declare. #2400

ghost opened this issue Nov 17, 2019 · 8 comments
Assignees
Labels
comp:react-native type:support user support questions

Comments

@ghost
Copy link

ghost commented Nov 17, 2019

TensorFlow.js version

1.3.2

TensorFlow.js react-native version

0.1.0-alpha.2

Browser version

react-native 0.59.8
expo sdk 35.0.0
expo version 3.7.1

Describe the problem or feature request

Hi, I follow the steps in the page https://github.com/tensorflow/tfjs/tree/master/tfjs-react-native for a expo managed app, but I get the following error

node_modules/@tensorflow/tfjs-converter/dist/src/data/compiled_api.ts: 
/Users/itachi/my-apps/react/react-native/mobile-net/node_modules/@tensorflow/tfjs-converter/dist/src/data/compiled_api.ts: 
Namespace not marked type-only declare. Non-declarative namespaces are only supported experimentally in Babel. 
To enable and review caveats see: https://babeljs.io/docs/en/babel-plugin-transform-typescript
  70 | }
  71 | 
> 72 | export namespace TensorShape {
     |                  ^^^^^^^^^^^
  73 |   /** Properties of a Dim. */
  74 |   export declare interface IDim {
  75 |     /** Dim size */
Failed building JavaScript bundle.

Code to reproduce the bug / link to feature request

These are the commands I've run

expo init mobile-net (-> Managed workflow)
cd mobile-net
expo install expo-gl
npm install @tensorflow/tfjs
npm install @tensorflow/tfjs-react-native@alpha
npm install @react-native-community/async-storage
npm install react-native-fs

Added the lines in the App.js file

import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-react-native';

then

expo start
@ghost
Copy link
Author

ghost commented Nov 23, 2019

Hi, I found the following solution.
I installed the packages

npm install typescript react-native-typescript-transformer

Then I create, in the root of the project the file metro.config.js as

module.exports = {
    transformer: {
        babelTransformerPath: require.resolve(
            'react-native-typescript-transformer',
        ),
    },
};

And the file tsconfig.json as

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true
    }
}

At the moment I have no problem

@tafsiri
Copy link
Contributor

tafsiri commented Nov 26, 2019

Hi @itachiuchiha91 thanks for letting us know. Is your project a typescript project? If so did you add skipLibCheck: true to your tsconfig.json?

Ideally you shouldn't need to transpile the typescript as the js is already bundled, but it looks like the resolver tries to load the typescript first.

@tafsiri
Copy link
Contributor

tafsiri commented Nov 26, 2019

@caisq Just out of curiosity, do you know why compiled_api.ts is copied into dist when building tfjs-converter? https://github.com/tensorflow/tfjs/blob/master/tfjs-converter/package.json#L57

@GaryZlobinskiy
Copy link

@itachiuchiha91 thank you for your solution. It worked for me like a charm.

@NickRance
Copy link

NickRance commented Feb 20, 2020

I had to add the following line to my tsconfig.json to prevent TypeError: {Module}.default is not a function errors

    "esModuleInterop": true,
{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "esModuleInterop": true,
    }
}

@guerrato
Copy link

@NickRance
I was working on it right now and it solved my problem!

Now I can go to sleep! heheheheh!

Thank you a lot!

@jeff3dx
Copy link

jeff3dx commented Mar 13, 2020

The error message is asking you to add "declare" to the namespace. You can defined your namespace like so:
declare namespace MyNamespace {...}
OR
export declare namespace MyNamespace {...}

@darrylyoung
Copy link

export declare namespace MyNamespace {...}

Thanks, @jeff3dx. That solved a related issue I was having.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:react-native type:support user support questions
Projects
None yet
Development

No branches or pull requests

7 participants