gpt4 book ai didi

reactjs - 使用导入类型时出现意外 token

转载 作者:行者123 更新时间:2023-12-04 11:04:17 31 4
gpt4 key购买 nike

我从 create-react-app 中弹出,我在使用 import type 时遇到问题当我运行测试站点时(使用 yarn start )。
Module parse failed: /project/src/web/MarkdownField.js Unexpected token (6:12)
You may need an appropriate loader to handle this file type.

当我使用 yarn flow ,该过程将无错误地完成。

.babelrc

{
"presets": ["flow", "es2015", "react", "stage-2"]
}

.flowconfig
[libs]
./flow-typed

[options]
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

[include]
./src/**

mdTypes.types.js
// @flow

import { propTypes } from 'redux-form';

export type FieldType = {
field: propTypes.fieldPropTypes
};

MarkdownField.js
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import MDE from 'medium-editor';
import MeMarkdown from 'medium-editor-markdown';
import type { FieldType } from '../mdTypes.types';

class MarkdownField extends React.PureComponent<void, FieldType> {

包.json
{
"name": "project",
"version": "0.0.1",
"private": false,
"dependencies": {
"medium-editor": "^5.23.2",
"medium-editor-markdown": "^2.6.0",
"react-markdown": "^2.5.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-form": "^7.0.4"
},
"devDependencies": {
"autoprefixer": "7.1.2",
"babel-cli": "^6.26.0",
"babel-core": "6.25.0",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^3.0.3",
"babel-preset-stage-2": "^6.24.1",
"babel-runtime": "6.26.0",
"chalk": "1.1.3",
"eslint": "4.4.1",
"eslint-config-react-app": "^2.0.1",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "^2.37.0",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.1.0",
"flow-bin": "^0.56.0",
"jest": "20.0.4",
"react": "^16.0.0",
"react-dev-utils": "^4.1.0",
"react-dom": "^16.0.0"
},
"scripts": {
"start": "node scripts/start.js",
"test": "node scripts/test.js --env=jsdom",
"build": "flow-remove-types src/ -d lib/",
"prepublish": "yarn run build"
},
"jest": {
"collectCoverageFrom": ["src/**/*.{js,jsx}"],
"setupFiles": ["<rootDir>/config/polyfills.js"],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.js?(x)",
"<rootDir>/src/**/?(*.)(spec|test).js?(x)"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest"
},
"transformIgnorePatterns": ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": ["web.js", "js", "json", "web.jsx", "jsx", "node"]
}
}

有什么建议?

最佳答案

我们有类似的设置并有相同的错误。您可能需要在 .eslintrc 中为 eslint 检查添加 e 插件像这样:

{
"extends": ["plugin:flowtype/recommended"],
"plugins": [
"flowtype"
]
}

关于reactjs - 使用导入类型时出现意外 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46576167/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com