使用wasm-pack new创建新项目失败求助(M1芯片环境)
wasm-pack new crypto报错的解决方案 以下是针对expected value at line 1 column 1报错的排查与解决步骤:
检查Rust工具链架构适配
执行rustup show确认当前工具链为stable-aarch64-apple-darwin,若为x86架构工具链,执行rustup default stable-aarch64-apple-darwin切换到M1原生arm64版本。同时用file $(which rustup)和file $(which cargo)验证输出包含Mach-O 64-bit executable arm64,确保工具链是原生适配的。清理wasm-pack缓存与异常配置
删除本地缓存目录:rm -rf ~/.cache/wasm-pack,若存在~/.wasm-pack/config.toml文件且内容异常,直接删除该配置文件。手动指定模板创建项目
报错可能是模板下载不完整导致解析失败,尝试手动指定官方模板地址:wasm-pack new crypto --template https://github.com/rustwasm/wasm-pack-template.git若仍失败,先克隆模板到本地再创建项目:
git clone https://github.com/rustwasm/wasm-pack-template.git wasm-pack new crypto --template ./wasm-pack-template重新安装并验证依赖
执行cargo install --force wasm-pack强制重装,确保安装过程无报错。同时检查cargo registry配置,执行cargo config get registry.index确认默认源为https://github.com/rust-lang/crates.io-index,若有自定义源,暂时切换回默认源测试。确认终端环境为原生arm64
打开终端后右键选择“显示简介”,取消勾选“使用Rosetta打开”,确保终端运行在M1原生模式。执行uname -m验证输出为arm64。
内容的提问来源于stack exchange,提问作者Eric MacFarland

