【Copilot极限实践日记】DAY 2: 使用Copilot/ChatGPT解决项目编译问题

这个系列之所以叫极限实践是因为我也不知道这是不是最佳实践。我现在尝试把ChatGPT用到极致,即几乎所有的具体编码或者写作都交由ChatGPT完成,看可以提升多少效率,或者降低效率。也看看能不能研究出更好的使用Copilot的方法。

名词介绍

平台和模型

讨论AI就必须加上平台和模型,否则就不客观。所以以下讨论都会标注平台和模型

Copilot

Copilot 就是微软出的使用ChatGPT的聊天机器人,你可以把它看作是ChatGPT的一种封装形式。你可以切换模型,目前可选的有Gemini,Claude和ChatGPT

Github Copilot

Github Copilot 是一款AI 编码助手。它把Copilot整合到了Github里面

我使用的模型是 GPT-4o

Github Copilot 的 VSCode 插件

Github开发了Github的Copilot插件。该插件通过跟Github Copilot联网实现在IDE内使用Copilot帮助程序员编码。目前支持VSCode和Intellij。

DAY 2 背景

原本今天的计划是使用Copilot尝试生成unit tests。但是由于我的node.js项目的依赖更新了,所以跟eslint有关的代码报错了。所以我索性把这个node.js项目的eslint从版本4升级成9,由于4采用的配置文件.eslintrc.js已经废弃了,我换成了新的配置文件 eslint.config.mjs。之后构建就一直出错。所以我就用Copilot和ChatGPT来帮我解决问题。

这是jenkins构建报的错

sh 复制代码
(node:163) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/jenkins/agent/workspace/xxxxxx/src/build/build.js:1
import copyfiles from 'copyfiles';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

我看到这个错误叫我在package.json里面 set "type": "module" ,我就照做了,然后项目就启动不起来了。我就知道我得问ChatGPT或者Copilot了。

步骤

ChatGPT(4o)

我首先想到的是ChatGPT因为jenkins是在项目以外的。我不知道Copilot能不能解决超过项目代码以外的问题。

Step 1 直接询问

一开始先用最懒的问法,直接把错误一贴就开问

复制代码
jenkins构建报错:

(node:163) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use node --trace-warnings ... to show where the warning was created)
/home/jenkins/agent/workspace/xxxxxx/src/build/build.js:1
import copyfiles from 'copyfiles';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

这是什么问题,要怎么解决

ChatGPT 回答

这个错误的核心问题是: 🔴 Jenkins 运行 build.js 时,Node.js 解析 import

语法失败,因为它仍然认为你的项目是 CommonJS,但 build.js 里用了 import 语法。

CommonJS,但 build.js 里用了 import 语法。 🔍 为什么会发生?

你的 build.js 代码里使用了: import copyfiles from 'copyfiles';

Node.js 默认使用 CommonJS,不支持 import,除非:

你的 package.json 里有 "type": "module"

文件扩展名是 .mjs(比如 build.mjs)

用 node --experimental-modules(旧方案,不推荐)

Jenkins 运行时,node 解析 build.js 时发现 import,但环境是 CommonJS,所以报错。

✅ 解决方案

你有几种方法可以修复这个问题,取决于你是否要保留 import 语法。 方案 1️⃣:改回 require()(最简单)

如果你不打算切换到 ESM,把 import 改成 CommonJS 的 require(): const copyfiles = require("copyfiles"); \ // 你的代码... 👉 适用于:你的项目主要还是 CommonJS(你之前也是用 require() 的)。 方案 2️⃣:让

build.js 运行在 ESM(ES 模块)

如果你希望继续使用 import 语法,需要让 Node.js 识别它: 方法 2.1:在 package.json 里加 "type":

"module" { "type": "module" }

📌 注意:这样会让整个项目变成 ESM,所有 require() 代码都要改成 import,否则可能引发其他报错。 方法 2.2:把

build.js 改成 .mjs

把文件改名: mv src/build/build.js src/build/build.mjs 然后 Jenkins

里调用 node src/build/build.mjs,这样 Node.js 会自动解析它为 ESM。

后面还有很长,因为太长了所以我就不贴到文章中了。而且整体格式很漂亮。给你看下它回答的格式

一次就得到了我想要的结果。我采用了方案1,然后问题就解决了。

Copilot(GPT-4o)

接下来尝试使用了GPT-4o模型的Copilot。照说模型相同回答应该不会差太多。

Step 1 直接询问

这次我尝试对Copilot问同样的问题

复制代码
jenkins build error

(node:163) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (Use node --trace-warnings ... to show where the warning was created) /home/jenkins/agent/workspace/xxxxxx/src/build/build.js:1 import copyfiles from 'copyfiles'; ^^^^^^

SyntaxError: Cannot use import statement outside a module at internalCompileFunction (node:internal/vm:77:18) at wrapSafe (node:internal/modules/cjs/loader:1288:20) at Module._compile (node:internal/modules/cjs/loader:1340:27) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49

how to fix it

Copilot 回答

它给的建议虽然也可以解决问题,但是我如果真的照它给的建议来改,会改变文件或者项目的属性,我可能会遇到更多的问题。这个回答有两个问题:

  • 它并没有给出所有回答
  • 它不会考虑解决方案的成本和得失

Step 3 增加询问细节

我对以上回答不满意,于是我追问,如果我不想按以上的所有方案,看它能否提供给我一个chatGPT给的方案

复制代码
If you prefer not to make major changes, you can use the CommonJS require syntax instead of the ES module import syntax. This way, you don't need to change the file extensions or update the package.json.

Copilot 回答

If you prefer not to make major changes, you can use the CommonJS

require syntax instead of the ES module import syntax. This way, you

don't need to change the file extensions or update the package.json.

build.js Update the import statement to use require instead of import.

build.js+5-4 By using require instead of import, you can avoid the

need to set "type": "module" in your package.json or rename your files

to .mjs. This should resolve the issue with minimal changes to your

codebase.

这回它给出了正确的回答。实际上我很惊讶Copilot的第一个回答跟直接问ChatGPT差别很大。相同的模型居然有这么大的差别,导致我怀疑我用的Copilot使用的4o模型不是一个完整版。

结论

  • 整体来说Copilot这次还是输给了ChatGPT,还是失败了。因为问Copilot不如问ChatGPT。
  • 在项目整体问题的解决上ChatGPT比Copilot强
  • Copilot不会衡量成本和收益
  • 你需要多追问Copilot来获得预期的答案

明天我再次尝试使用Copilot生成unit tests.

相关推荐
jerrywus1 小时前
别再让 AI 盲写代码了:我用 gstack 把"灵感"变"可上线"
chatgpt·agent·claude
Agent产品评测局4 小时前
中小企业数字化转型,优先选 RPA 还是 AI Agent?:2026企业自动化架构选型深研
人工智能·ai·chatgpt·自动化·rpa
AI英德西牛仔1 天前
deepseek怎么导出文档
人工智能·ai·chatgpt·deepseek·ds随心转
成都被卷死的程序员1 天前
从ChatGPT到Open Claw:生成式AI的跃迁之路
人工智能·chatgpt
JavaPub-rodert1 天前
2026年国内 Codex 安装教程和使用教程:GPT-5.4 完整指南
gpt·chatgpt·openai·codex·gpt5.4
小仓桑1 天前
【Agent智能体项目实战二】通义千问流式输出:实现像 ChatGPT 一样逐字打印效果
人工智能·chatgpt·agent
柯儿的天空1 天前
【OpenClaw 全面解析:从零到精通】第 019 篇:GoClaw 企业版——从开源到商业化的演进之路
gpt·开源·aigc·copilot·ai编程·ai写作·agi
卡尔AI工坊1 天前
copilot更新:本地、背景、云;Claude、Codex
人工智能·经验分享·chatgpt·软件工程·copilot·ai编程
AI英德西牛仔1 天前
deepseek导出word排版
人工智能·ai·chatgpt·deepseek·ds随心转
智算菩萨1 天前
ChatGPT在非洲主要国家教育中的应用:效益、接受度与伦理挑战——基于2022-2024年文献的系统综述精读
论文阅读·人工智能·gpt·深度学习·ai·chatgpt·论文笔记