flow-runtime icon indicating copy to clipboard operation
flow-runtime copied to clipboard

SyntaxError: Unexpected token import (from flow-runtime)

Open OKNoah opened this issue 6 years ago • 2 comments

This is a:

  • [x] Bug Report
  • [x] Question

Which concerns:

  • [x] flow-runtime
  • [x] babel-plugin-flow-runtime

What is the current behaviour?

The complete configuration is here: https://github.com/OKNoah/flow-runtime-test

package.json

{
  "presets": [
    "stage-2",
    "react"
  ],
  "plugins": [["flow-runtime"], "transform-decorators-legacy"]
}

index.js

// @flow-runtime

type User = {
  name: string
};

console.log('henlo')
[nodemon] starting `node -r babel-register index.js`
/Users/noah/Projects/flow-runtime-test/index.js:1
(function (exports, require, module, __filename, __dirname) { import t from 'flow-runtime';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at loader (/Users/noah/Projects/flow-runtime-test/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/noah/Projects/flow-runtime-test/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
[nodemon] app crashed - waiting for file changes before starting...

What is the expected behaviour?

Should compile without errors and console log.


Which package versions are you using?

"babel": "^6.23.0",
"babel-plugin-flow-runtime": "^0.15.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"flow-runtime": "^0.16.0"

OKNoah avatar Dec 31 '17 17:12 OKNoah

The fix is to simply add babel-preset-env.

{
  "presets": [
    "env",
    "stage-2",
    "react"
  ],
  "plugins": [["flow-runtime"], "transform-decorators-legacy"]
}

and

npm install --dev babel-preset-env

OKNoah avatar Dec 31 '17 17:12 OKNoah

Related to #207

skeggse avatar Nov 19 '19 01:11 skeggse