本文介绍了包裹 SemVer 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我之前曾多次使用 Parcel,但从未遇到过问题.这一次它抛出了一些关于 SemVer 版本控制的愚蠢错误,我真的很想找到解决这个问题的解决方案.

我开始了新项目:安装了带有 npm init 的 npm(没有其他选项),然后安装了 Parcel npm install --save-dev parcel-bundler 和然后创建了我的文件夹结构:

--node_modules
--index.html
--index.js

这是我的 package.json:

{名称":游乐场",版本":1.0.0",描述":",主要":index.js",脚本":{开发":包裹索引.html";},作者":",许可证":ISC",开发依赖":{包裹打包机":^1.12.4"}}

我已经配置了默认的 npm 脚本来运行 Parcel:"dev":"parcel index.html" 并运行它.一切正常,但是当我通过 <script src="/index.js></script> 在 index.html 中连接我的 index.js 时,它会抛出很大的错误,说:

D:\workingSpace\playground\index.js:无效版本:未定义在新的 SemVer (D:\workingSpace\playground\node_modules\@babel\preset-env\node_modules\semver\semver.js:314:11)在比较 (D:\workingSpace\playground\node_modules\@babel\preset-env\node_modules\semver\semver.js:647:10)在 lt (D:\workingSpace\playground\node_modules\@babel\preset-env\node_modules\semver\semver.js:688:10)在 D:\workingSpace\playground\node_modules\@babel\preset-env\lib\index.js:276:22在 Object.default (D:\workingSpace\playground\node_modules\@babel\helper-plugin-utils\lib\index.js:22:12)在 getEnvPlugins (D:\workingSpace\playground\node_modules\parcel-bundler\src\transforms\babel\env.js:62:34)在 getEnvConfig (D:\workingSpace\playground\node_modules\parcel-bundler\src\transforms\babel\env.js:12:25)在 async getBabelConfig (D:\workingSpace\playground\node_modules\parcel-bundler\src\transforms\babel\config.js:32:19)在 async babelTransform (D:\workingSpace\playground\node_modules\parcel-bundler\src\transforms\babel\transform.js:6:16)在异步 JSAsset.pretransform (D:\workingSpace\playground\node_modules\parcel-bundler\src\assets\JSAsset.js:83:5)

目前我使用的是 Node v14.6.0,因此它是 npm 版本 - 6.14.11

我以前从未遇到过这个错误,请帮助T_T

解决方案

这是 Parcel 最新版本中的一个已知问题.

这个问题的解决方案是恢复到版本1.12.3,或者更新到Parcel的版本2.您可以通过以下方式执行第一个解决方案:

npm uninstall parcel-bundlernpm i --save-dev [email protected]

第二种解决方案可以这样完成:

npm i --save-dev parcel@next

如果您决定使用 Parcel 的夜间版本,您可能需要稍微重构一下代码以防止破坏性更改.查看更多关于如何迁移到 Parcel v2/每晚此处.

此处了解该问题.


更新 #1:28/05/2021

截至撰写本文时 (28/05/2021),Parcel 团队似乎一直在致力于修复.虽然我没有亲自检查更新是否正常工作,但这个答案仍然是一个非常可行和可行的解决方案.

So, I've used Parcel multiple times before and I've never had an issue with it.This time it throws some stupid errors about SemVer versioning and I'm literally loosing my mind trying to find a solution which would fix this problem.

I've started new project: installed npm w/ npm init (no additional options), then installed parcel npm install --save-dev parcel-bundler and then created my folder structure:

Here is my package.json:

{
  "name": "playground",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "parcel index.html"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.12.4"
  }
}

I've configured default npm script to run parcel: "dev": "parcel index.html" and run it.Everything works fine, however when I connect my index.js in index.html via <script src="/index.js"></script> it throws big fat error, saying:

Currently I'm using Node v14.6.0 and accordingly it's npm version - 6.14.11

I've never faced this bug before, please help T_T

解决方案

This is a known problem in the newest version of Parcel.

The solution of this problem was to revert back to version 1.12.3, or by updating to the version 2 of Parcel. You can do the first solution by:

npm uninstall parcel-bundler
npm i --save-dev [email protected]

The second solution could be done like this:

npm i --save-dev parcel@next

You might have to refactor your code a bit to prevent breaking changes if you decided to use the nightly version of Parcel. Check more about how to migrate to Parcel v2 / nightly here.

Catch up with that issue here.


Update #1: 28/05/2021

It seems that Parcel team has been working on a fix, as of the time of writing (28/05/2021). While I have not personally checked if the update has worked properly or not, this answer is still very much a viable and feasible solution.

这篇关于包裹 SemVer 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 02:44