nodejs / nodejs/node

Support clearing Node.js cache for package.json

未关闭
#54,924 10 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request loaders never-stale
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

What is the problem this feature will solve?

When a long-running Node.js process is active and a package.json file is modified (for example, by adding "type": "module"), Node.js does not detect this change. It continues treating the package as CommonJS, which results in an error like Unexpected token 'export' when attempting to use ES modules.

This is crucial for us at bit, where we run a background process called “bit server” that manages the local development workspace. Among its tasks is creating new web components, which initially have a package.json without "type": "module". If the component is later determined to be ESM, the package.json is updated accordingly. (Explaining why this can’t be handled differently is beyond the scope of this feature request).

What is the feature you are proposing to solve the problem?

I propose adding an API that allows clearing the cached information related to the package.json of a specific module (or optionally clearing the cache for all modules). Either option would solve the issue.

What alternatives have you considered?

Restarting the Node.js process, but this results in a poor user experience.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

issue 中没有指定文件或测试。首先跟踪 Node.js 在哪里缓存 package.json 的模块元数据,然后定义一个用于清除单个模块缓存并可选择清除所有模块缓存的 API;完成标准是在不重启进程的情况下识别出 package 类型的变化。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
backend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。