You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Parcel构建生成的导入在执行构建模块时失败的原因排查

前言

我刚接触Parcel和打包工具,可能存在操作失误。
由于我要打包给Node.js执行的服务端代码,因此遵循了Parcel构建库的指南。
我的package.json包含以下内容(已移除无关细节):

{
  "source":"bin/server.js",
  "module":"dist/server.js"
  "scripts":{
    "build": "parcel build"
  }
  "type":"module"
}

主要问题

当我使用npm run build构建应用时,一切生成正常,无报错,仅耗时约2秒。
但尝试运行node .\bin\server.js时,抛出以下错误:

import {exit as $a7IyA$exit, on as $a7IyA$on} from "process";

------------------------------^^--------------------------------------------------

SyntaxError: The requested module 'process' does not provide an export named 'on'

补充说明:使用Parcel打包前,应用运行正常,且server.js文件的首个导入语句如下(即报错位置):

import {exit as $a7IyA$exit, on as $a7IyA$on} from "process";

更新:

查阅Parcel的Targets文档后,我更确信它可用于后端打包,于是尝试将package.json更新为以下内容:

{
  "targets": {
    "server": {
      "source": "bin/server.js",
      "context": "node",
      "distDir": "./dist",
      "includeNodeModules": true,
      "outputFormat": "esmodule"
     }
  },
  "scripts":{
    "build": "parcel build"
  }
  "type":"module"
}

这让我取得了一些进展,但现在又出现了以下错误:

Uncaught ReferenceError ReferenceError: $2az4q$relative is not defined

内容的提问来源于stack exchange,提问作者Rigatoni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 00:10:33