导入React SyntaxError:意外的标识符-从另一个模块导入React组件时

时间:2019-11-13 09:01:28

标签: reactjs npm

我试图通过将我的存储库之一作为模块导入,然后导入这些组件来共享我的react组件,但出现错误:

'import React from 'react'
        ^^^^^

SyntaxError: Unexpected identifier'

我尝试了多个组件,当我尝试导入它们时,它们都会出现相同的错误。

我要导入的

组件-

import React from 'react'
import ImportedSearch from 'otherrepository/src/includes/search'
import config from '../config/search'

class Search extends React.Component {
  render () {
    const { domain } = this.props
    return (
      <ImportedSearch
        config={config}
        domain={domain}
       />
    )
  }
}

export default Search

otherrepository / src / includes / search-

import React from 'react'
import config from '../config/search/'

class Search extends React.Component {
  render () {
    const { domain } = this.props
    return (
      <div className='container'>
        <div className='tabs ui-tabs ui-widget ui-widget-content ui-corner-all'>
          <div className='search'>
            <div className='container'>
               <input placeholder={domain} />
              </div>
            </div>
          </div>
      </div>
    )
  }
}

export default Search

package.json

{
  "name": "repo",
  "platform": "custom",
  "ci": "dockyard",
  "license": "UNLICENSED",
  "scripts": {
    "ci": "echo 'Optional CI step goes here'"
  },
  "dependencies": {
    "@babel/core": "7.7.2",
    "@babel/plugin-syntax-dynamic-import": "^7.2.0",
    "@babel/plugin-transform-classes": "7.7.0",
    "@babel/plugin-transform-runtime": "7.6.2",
    "@babel/preset-env": "7.7.1",
    "@babel/preset-react": "7.7.0",
    "@babel/register": "7.7.0",
    "babel-loader": "8.0.6",
    "otherrepository": "github:sara/otherrepository#staging"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/repo.git"
  },
  "domain": "www.domain.com",
  "sideEffects": false,
  "_moduleDirectories": [
    "src/config",
    "src/plugins",
    "src/includes",
    "src/stores",
    "src",
    "node_modules"
  ],
  "devDependencies": {
    "chai": "4.2.0",
    "chai-as-promised": "7.1.1",
    "chokidar": "3.3.0",
    "dirty-chai": "2.0.1",
    "enzyme": "3.10.0",
    "enzyme-adapter-react-16": "1.15.1",
    "eslint": "6.6.0",
    "eslint-config-standard": "14.1.0",
    "eslint-plugin-import": "2.18.2",
    "eslint-plugin-mocha": "6.2.1",
    "eslint-plugin-node": "10.0.0",
    "eslint-plugin-promise": "4.2.1",
    "eslint-plugin-standard": "4.0.1",
    "mocha": "5.2.0",
    "nyc": "14.1.1",
    "opn": "5.5.0",
    "reload": "3.0.3",
    "sinon-chai": "3.3.0",
    "webpack-bundle-analyzer": "3.6.0"
  },
  "config": {
    "port": 13000
  }
}

0 个答案:

没有答案