我有一个名为Frontend-Core-Components
的项目,其中包含我的App组件。
我有另一个项目(现在叫它Alpha
),其中包含AlphaApiService
,我通过它的道具传递给App组件,我在Alpha的index.tsx
中进行了此操作
Alpha
使用Create-react-app,我使用脚本来修改Webpack配置,以将Frontend-core-components作为模块添加,在此Webpack配置中,我使用resolve.alias
映射从Alpha导入的内容[C0 ]到index.tsx
。
似乎一切正常,除非我从Alpha项目运行构建,否则会遇到以下情况。
Frontend-Core-Components
任何想法?
导入之前,您需要先编译导入模块。
我建议您检出此项目以创建React组件库。
SyntaxError: /Users/coolguy/project/alpha/src/index.tsx: Unexpected token (9:11)
7 |
8 | window.onload = () => {
> 9 | render(<App apiService={new AlphaApiService()} />,
document.getElementById('root'))
| ^
10 | }
11 |
似乎您已忘记https://github.com/KaiHotz/react-rollup-boilerplate。如果不使用import React from "react"
,则会发生类似错误:
jsx
const render = () => null render(<App />, document.getElementById("root"));