Vue3安装pixi.js 项目无法识别 ?. 语法,导致报错Module parse failed: Unexpected token

博客指出pixi.js 7.2.4版本导入组件库时出现编译问题,报错提示需合适加载器处理文件。原因是导入的组件库为源码,需webpack将es6、es7特性转换为es5。解决方案是在vue.config.js里添加transpileDependencies配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 error  in ./node_modules/@pixi/assets/lib/resolver/parsers/resolveTextureUrl.mjs

Module parse failed: Unexpected token (9:62)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   test: loadTextures.test,
|   parse: (value) => ({

>     resolution: parseFloat(settings.RETINA_PREFIX.exec(value)?.[1] ?? "1"),
|     format: value.split(".").pop(),
|     src: value

 @ ./node_modules/@pixi/assets/lib/index.mjs 20:0-77 20:0-77 

pixi.js 是最新版本,7.2.4

低版本没发现有问题

问题原因:
因为导入的组件库是直接上源码的,必须告知webpack,需要编译一下这个库,让源码中的es6、es7的特性转换为es5

解决方案:
1.在vue.config.js 里面加上 transpileDependencies: [‘/@pixi/’]

module.exports = {

     transpileDependencies: [‘/@name/’]

}

name    找报错的node_modules 里依赖的路径   @ ./node_modules/@pixi/assets/lib/index.mjs 20:0-77 20:0-77 

 参考:项目无法识别 ?. 语法,导致报错Module parse failed: Unexpected token

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值