Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Unexpected crash: dts-gen -m aws-amplify-react-native: "SyntaxError: Cannot use import statement outside a module" #152

Open
dantasfiles opened this issue Feb 13, 2020 · 1 comment

Comments

@dantasfiles
Copy link

> dts-gen -m aws-amplify-react-native
Unexpected crash! Please log a bug with the commandline you specified.
C:\...\node_modules\aws-amplify-react-native\dist\index.js:14
import { default as AmplifyCore, I18n } from 'aws-amplify';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1067:16)
    at Module._compile (internal/modules/cjs/loader.js:1115:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)       
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\...\AppData\Roaming\npm\node_modules\dts-gen\bin\lib\run.js:58:67)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)  
@dantasfiles
Copy link
Author

dantasfiles commented Feb 13, 2020

The problem is require doesn't support ES6 modules.

result = guess.generateModuleDeclarationFile(args.module, require(args.module));

The solution in #42 (comment) uses @babel/register:

The require hook will bind itself to node's require and automatically compile files on the fly.

  • Run npm install @babel/core @babel/register --save-dev
  • Add to the top of lib/run.js
require("@babel/register")({
  ignore: [],
  presets: ["INSERT YOUR PRESET HERE"]
});

I used module:metro-react-native-babel-preset as my preset.

  • Run npm run build
  • Run npm link
  • Run dts-gen -m aws-amplify-react-native

However, it kept on wanting me to install more and more packages, aws-amplify-react-native -> aws-amplify -> react-native.
Finally, it crashed with an Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules at invariant error.

This seems to be too complex a use-case for dts-gen so I'm going to give up for now.

ETA: I hit "close issue" by mistake.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant