无法在Laravel项目中安装Flow for React

时间:2018-12-28 21:02:21

标签: reactjs laravel flowtype laravel-mix

我正在开发Laravel应用程序。对于前端,我正在使用React JS。现在,我正在尝试将Flow集成到我的项目中。我点击了此链接https://flow.org/en/docs/install/。但是没有用。

我在根文件夹中运行此命令

npm install --save-dev babel-cli babel-preset-flow

然后在项目根文件夹中创建具有以下内容的.babelrc文件

{
  "presets": ["flow"]
}

然后我运行此命令

npm install --save-dev flow-bin

这是我的package.json

{
    "private": true,
    "scripts": {
        "flow": "flow",
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@babel/preset-react": "^7.0.0",
        "axios": "^0.18.0",
        "babel-cli": "^6.26.0",
        "babel-preset-flow": "^6.23.0",
        "babel-preset-react": "^6.23.0",
        "bootstrap": "^4.2.1",
        "cross-env": "^5.1",
        "flow-bin": "^0.89.0",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "react": "^16.2.0",
        "react-dom": "^16.7.0",
        "react-scripts": "^2.1.2",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0"
    },
    "dependencies": {
        "@coreui/coreui": "github:coreui/coreui",
        "@coreui/coreui-plugin-chartjs-custom-tooltips": "github:coreui/coreui-plugin-chartjs-custom-tooltips",
        "@coreui/react": "^2.1.2",
        "classnames": "^2.2.6",
        "core-js": "^2.6.1",
        "enzyme": "^3.8.0",
        "flag-icon-css": "^3.2.1",
        "font-awesome": "^4.7.0",
        "node-sass": "^4.11.0",
        "prop-types": "^15.6.2",
        "react-app-polyfill": "^0.1.3",
        "react-loadable": "^5.5.0",
        "react-redux": "^6.0.0",
        "react-router": "^4.3.1",
        "react-router-config": "^4.4.0-beta.6",
        "react-router-dom": "^4.3.1",
        "react-test-renderer": "^16.7.0",
        "reactstrap": "^6.5.0",
        "redux": "^4.0.1",
        "redux-thunk": "^2.3.0",
        "simple-line-icons": "^2.4.1"
    }
}

然后我运行这个

npm run flow init

然后这个

npm run flow

运行上面的命令时出现此错误。

> @ flow /Users/wai/Desktop/easy-eat
> flow

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ vendor/symfony/translation/Tests/fixtures/empty.json:1:1

Unexpected end of input

     1│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ vendor/symfony/translation/Tests/fixtures/malformed.json:2:11

Unexpected string

     1│ {
     2│     "foo" "bar"
     3│ }



Found 2 errors
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ flow: `flow`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the @ flow script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/wai/.npm/_logs/2018-12-28T21_01_36_563Z-debug.log

缺少什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

我也遇到了这个问题。默认情况下,Flow将检查项目中的所有目录。您可以通过在项目的根目录中创建一个.flowconfig文件来解决此错误。 (运行yarn run flow init也会为您创建此文件)

请确保通过此配置忽略vendor文件夹。我的配置如下:

[ignore]
.*/vendor/.*

[include]

[libs]

[lints]

[options]

[strict]