我只是React的新开发人员。我刚刚使用create-react-app插件启动了一个新的应用程序。之后我定制了自己的应用程序组件,但这是使用一些第三方组件使npm run test
(react-scripts test --env = jsdom)失败并显示错误:
SyntaxError: Unexpected token import
此错误仅发生在我正在使用的node_modules上的依赖项内导入。例如,它没有给出错误
import React, { Component } from 'react';
由于我使用的是create-react-app插件,因此我不知道需要更改哪些内容才能通过。但是,它似乎与某些babel配置缺失有关。
我认为我不需要安装babel-jest依赖项,因为它嵌入了create-react-app。
我也试图执行,但没有成功:
npm run test -- --no-cache
package.json文件:
{
"name": "dhis2-hello-world",
"version": "0.1.0",
"private": true,
"dependencies": {
"d2": "^28.3.0",
"d2-manifest": "^1.0.0",
"d2-ui": "^28.0.8",
"d2-utilizr": "^0.2.15",
"loglevel": "^1.6.0",
"material-ui": "^0.20.0",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.0.17",
"rxjs": "^5.5.5"
},
"scripts": {
"prestart": "d2-manifest package.json ./public/manifest.webapp",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"manifest.webapp": {
"name": "DHIS2 App Template",
"description": "DHIS2 App Template",
"icons": {
"48": "icon.png"
},
"developer": {
"url": "",
"name": "DHIS2"
},
"activities": {
"dhis": {
"href": ".."
}
}
}
}
错误:
/node_modules/d2-ui/lib/app-header/HeaderBar.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import PropTypes from 'prop-types';
PropTypes正在d2-ui的组件上导入,该组件正在App组件中导入,如下所示:
import React, { Component } from 'react';
import HeaderBarComponent from 'd2-ui/lib/app-header/HeaderBar';
我一直在寻找一种方法来解决它,而无需弹出项目。
有人能给我一些如何解决这个问题的线索吗?
非常感谢!