
一些时候,因为一些依赖依赖的依赖版本比较低,会导致一些莫名的问题,比如下面这个,编译时 @react-spring 的报错:
Failed to compile.
./node_modules/@react-spring/web/dist/esm/index.js 113:11
Module parse failed: Unexpected token (113:11)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| this.transforms = i;
| }
> _value = null;
| get() {
| return this._value || (this._value = this._get());搜了一下,这个报错还是非常典型的,但是排查起来就非常头大,即使在 package.json 中指定了依赖版本也无济于事。
这时候可以派 resolutions 出厂,解决这个问题。需要注意的是, resolutions 需要搭配 yarn 使用。
在 package.json 中添加 resolutions 配置:
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"left-pad": "1.0.0",
"c": "file:../c-1",
"d2": "file:../d2-1"
},
"resolutions": {
+ "@react-spring/web": "9.6.1"
}
}package.json 文件里的 resolutions 字段用于解析选择性版本,可以用来自定义依赖版本。
这样就解决的编译时的依赖报错问题了。
本文关键词:依赖报错,依赖版本报错,Module parse failed: Unexpected token (113:11),编译时@react-spring报错
未经允许不得转载:w3h5-Web前端开发资源网 » 使用package.json文件里的resolutions,解决依赖版本问题导致的报错