V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
JustSong
V2EX  ›  JavaScript

求助, React 编译时遇到问题,非常离谱

  •  
  •   JustSong · 2021-02-23 17:02:23 +08:00 · 1546 次点击
    这是一个创建于 1130 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目是用 React Create App 创建的,编译的命令为:react-scripts build, 报错:

    gitpod /workspace/blog/admin $ npm run build
    
    > [email protected] build
    > react-scripts build
    
    Creating an optimized production build...
    Failed to compile.
    
    ./src/components/Users.js
      Line 109:3:  'fetchUserStatus' is not defined  no-undef
      Line 124:3:  'fetchData' is not defined        no-undef
      Line 140:3:  'addUser' is not defined          no-undef
      Line 144:3:  'deleteUser' is not defined       no-undef
      Line 157:3:  'editUser' is not defined         no-undef
    

    离谱点在于:

    1. 我在本地( Windows 10 ),WSL ( Ubuntu 20.04 )以及服务器( Ubuntu 16.04 )上编译都是没问题的。
    2. 但是 Heroku 上部署的版本编译时就出现上述报错,Gitpod 上也是如此,docker 里构建也是如此。
    3. 之前的版本 Heroku 上是可以成功编译的,但是我现在用 Gitpod 切换到之前的版本,发现也不行了。。

    项目地址是: https://github.com/songquanpeng/blog/tree/master/admin

    注意是 admin 文件夹中的那个。

    9 条回复    2021-02-23 17:35:48 +08:00
    azcvcza
        1
    azcvcza  
       2021-02-23 17:10:00 +08:00   ❤️ 1
    改一下 eslint 的配置?把警告等级调一下
    shintendo
        2
    shintendo  
       2021-02-23 17:13:34 +08:00   ❤️ 1
    考虑一下文件名大小写问题?是否曾经存在过小写的 users.js ?
    JustSong
        3
    JustSong  
    OP
       2021-02-23 17:19:38 +08:00
    @azcvcza 谢谢,解决了,加了 "no-undef": "off" 之后可以编译成功了,但是在不同的地方上编译有不一致的行为就离谱
    JustSong
        4
    JustSong  
    OP
       2021-02-23 17:20:06 +08:00
    @shintendo 不是,我本地测试是没问题的
    azcvcza
        5
    azcvcza  
       2021-02-23 17:24:37 +08:00   ❤️ 1
    @JustSong 因为不同环境打包用的 eslint 默认可能不一样吧,看这个警告估计。
    shintendo
        6
    shintendo  
       2021-02-23 17:25:29 +08:00   ❤️ 1
    @JustSong 我碰到过类似的问题,排查下来是因为 windows 大小写不敏感,linux 大小写敏感导致的
    JustSong
        7
    JustSong  
    OP
       2021-02-23 17:27:13 +08:00
    @azcvcza 我确实没把 yarn.lock 给加到仓库中,是这个原因导致的不一致吗?
    source
        8
    source  
       2021-02-23 17:27:15 +08:00   ❤️ 1
    @shintendo #6 我也怀疑是这个
    azcvcza
        9
    azcvcza  
       2021-02-23 17:35:48 +08:00   ❤️ 1
    @JustSong 该锁还是要锁,不然哪天 update 之后,工程就起不来了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2889 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:34 · PVG 19:34 · LAX 04:34 · JFK 07:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.