【发布时间】:2022-02-13 02:49:50
【问题描述】:
我最近刚刚尝试创建新的 npm 包。在我的导入中,它说module has no exports。我已将组件导出到 dist 文件夹内的 index.js 中。
这是我的项目结构
- dist
- components
- MyComponent.tsx
- index.js
package.json
编译前我的index.js
import MyComponent from "./components/MyComponent";
export {MyComponent}
我的package.json
{
"name": "my-test-npm",
"homepage": "https://github.com/ganinw13120/my-test-npm",
"main": "dist/index.js",
"module": "dist/index.js",
"bin": "dist/index.js",
"version": "0.1.13",
"dependencies": {
"@babel/polyfill": "^7.12.1",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.24",
"@types/node": "^12.20.37",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@types/uuid": "^8.3.3",
"bignumber.js": "^9.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"styled-components": "^5.3.3",
"typescript": "^4.5.3",
"uuid": "^8.3.2",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "rm -rf dist && NODE_ENV=production babel src/lib --out-dir dist --copy-files",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.8",
"@types/styled-components": "^5.1.17"
},
"files": [
"dist",
"package.json"
]
}
在我的错误中,它还说Field 'browser' doesn't contain a valid alias configuration 然后是dist 文件夹上的我的组件路径。似乎在 dist 文件夹中找不到我的组件,该文件夹已包含在内。
【问题讨论】:
-
你解决了这个问题吗? @Gan Mongklakorn
-
不,还在寻找。你有什么线索吗?
标签: reactjs typescript npm package.json