package.json 是用 yarn cli 创建的。当我尝试构建它时它失败了。如果我删除 "main": "src/index.js"
它会起作用。 src/index.js
存在,但目前它是一个空文件。
我是否需要指定我的包的路径或者为什么会抛出错误?将路径更改为错误消息中建议的路径也不起作用。
package.json
{
"name": "project",
"version": "0.1.0",
"description": "",
"main": "src/index.js",
"source": "src/index.html",
"browserslist": "supports es6-module",
"scripts": {
"start": "parcel --open chrome",
"build": "parcel build"
},
"repository": "",
"author": "",
"license": "MIT",
"dependencies": {
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0"
},
"devDependencies": {
"parcel": "^2.0.0-rc.0"
}
}
输出
$ parcel build
🚨 Build failed.
@parcel/namer-default: Target "main" declares an output file path of "src/index.js" which does not match the compiled bundle type "html".
.../project/package.json:5:11
4 | "description": "project",
> 5 | "main": "src/index.js",
> | ^^^^^^^^^^^^^^ Did you mean "src/index.html"?
6 | "source": "src/index.html",
7 | "scripts": {
💡 Try changing the file extension of "main" in package.json.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
最佳答案
package.json
中的 main
字段旨在供库开发人员使用(例如,如果您正在构建一个要发布到 npm 以供使用的包由他人)。在此上下文中,它指定了 output 目标 - 即 parcel 应该放置优化的 commonjs javascript 包的位置。 (参见 high-level documentation 和 detailed documentation)。
在你的情况下,你似乎正在构建一个应用程序,而不是一个库,所以我建议完全删除 main
字段,这应该可以解决你看到的错误。
关于javascript - package.json 中 main 的路径应该指向哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68884914/