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

使用npm link链接的包在create-react-app中出现webpack导出错误

本地开发React Hook在CRA项目中测试时导出找不到的问题

我正在本地开发一个React Hook,尝试在相邻目录example/下的create-react-app(CRA)项目中测试,但导入该链接模块时出现以下错误:

Attempted import error: 'usePleaseStay' is not exported from 'react-use-please-stay' (imported as 'usePleaseStay').
ERROR in ./src/App.tsx 10:2-15
export 'usePleaseStay' (imported as 'usePleaseStay') was not found in 'react-use-please-stay' (module has no exports)

ERROR in ./src/App.tsx 14:10-23
export 'usePleaseStay' (imported as 'usePleaseStay') was not found in 'react-use-please-stay' (module has no exports)

相关代码

App.tsx代码

import React from 'react';
import { usePleaseStay } from 'react-use-please-stay';

function App() {
  usePleaseStay(["Title One!", "Title Two!", "Title Three?!?"]);
  return (
    <></>
  );
}

export default App;

按住cmd点击react-use-please-stay跳转的文件内容

这是Hook源码中dist/index.d.ts的内容,明确存在导出:

export { usePleaseStay } from './hooks/usePleaseStay';

链接模块状态验证

执行npm ls --location=global --depth=0 --link=true的输出:

react-use-please-stay@1.0.0 -> ./../../../../../projects/react-use-please-stay

请问这是什么原因导致的?是否是create-react-app过度隐藏webpack配置引发的问题?恳请提供帮助。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 08:05:25