V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
vinsony
V2EX  ›  Node.js

为啥不能用 let path = require('path');

  •  
  •   vinsony · 2016-02-17 23:24:59 +08:00 · 4437 次点击
    这是一个创建于 2961 天前的主题,其中的信息可能已经有所发展或是发生改变。
    let fs = require('fs');
    //这样没问题


    let path = require('path');
    //这句就报错 Uncaught TypeError: Identifier 'path' has already been declared
    path 非得用 var 才行么...
    环境是 NW.js
    8 条回复    2016-02-18 18:33:03 +08:00
    reverland
        1
    reverland  
       2016-02-17 23:51:42 +08:00
    额。。。这应该是 nw.js 的问题。。
    shyling
        2
    shyling  
       2016-02-17 23:54:33 +08:00 via Android
    已经被定义了?重复了?还是换个名字
    plqws
        3
    plqws  
       2016-02-17 23:59:51 +08:00
    换个名字吧, let 和 var 的作用域不一样, electron 可能已经声明过了…
    tinyhill
        4
    tinyhill  
       2016-02-18 00:25:59 +08:00
    let 是不能重定义的
    adspe
        5
    adspe  
       2016-02-18 10:50:11 +08:00
    你不用 const ?
    vinsony
        6
    vinsony  
    OP
       2016-02-18 14:52:44 +08:00
    @adspe const 也一样.
    js 第一行就是这个 require ,不可能是重复定义
    vinsony
        7
    vinsony  
    OP
       2016-02-18 15:02:27 +08:00
    换成 node 正常, NW.js 坑爹啊
    JohnSmith
        8
    JohnSmith  
       2016-02-18 18:33:03 +08:00
    打印一下看看有没有被定义
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3313 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:20 · PVG 21:20 · LAX 06:20 · JFK 09:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.