镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

stderr redirection breaks require #11257

Description

@michaelglass
  • Version: 7.5.0
  • Platform: Darwin Kernel Version 16.5.0 (mac os sierra)

related workaround: rtfeldman/node-test-runner#106, rtfeldman/node-test-runner@959fda0

We noticed that when redirecting stderr AND receiving input script via pipe, require doesn't work with packages in package.json.

Minimal test case: (given a package.json that includes ajv).

echo "require('ajv')" | node &> js.out || cat js.out

expected output: nothing, it's just a require

actual output:

fs.js:56
    assertEncoding(options.encoding);
    ^

TypeError: assertEncoding is not a function
    at getOptions (fs.js:56:5)
    at Object.realpathSync (fs.js:1468:13)
    at toRealPath (module.js:130:13)
    at tryFile (module.js:126:22)
    at tryPackage (module.js:107:10)
    at Function.Module._findPath (module.js:183:20)
    at Function.Module._resolveFilename (module.js:468:25)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

also tested on another Ubuntu 14.04 server. Was not a problem using node 6.9.5

Activity

  1. added
    confirmed-bugIssues and PRs for confirmed bugs.
    fsIssues and PRs related to file-system APIs and the fs module.
    on Feb 9, 2017
  2. addaleax commented on Feb 9, 2017

    @addaleax
    Member

    Thanks for reporting this! Seems like some kind of circular dependency in the core module to me…

  3. self-assigned this
    on Feb 9, 2017
  4. avatar-lavventura commented on Jun 12, 2017

    @avatar-lavventura

    I have the same error. Running a python code on the background, which makes pipe to node.
    nohup python hello.py & . Inside python code I just called a node script. Original code works without nohup.

    Something like this:
    os.popen( val + "| node & echo $! >" + constants.LOG_PATH + "/my-app.pid").read().

            assertEncoding(options.encoding);
            ^
        
        TypeError: assertEncoding is not a function
            at getOptions (fs.js:58:5)
            at Object.realpathSync (fs.js:1564:13)
            at toRealPath (module.js:130:13)
            at Function.Module._findPath (module.js:178:22)
            at Function.Module._resolveFilename (module.js:468:25)
            at Function.Module._load (module.js:418:25)
            at Module.require (module.js:498:17)
            at require (internal/module.js:20:19)
            at [stdin]:1:13
            at ContextifyScript.Script.runInThisContext (vm.js:23:33)
        fs.js:58
    
  5. p3x-robot commented on Sep 19, 2017

    @p3x-robot

    i have this error as well, so it is because of 8.5?

  6. BridgeAR commented on Sep 23, 2017

    @BridgeAR
    Member

    I can not reproduce this from 8.4 on but I do not know what might have fixed it.

    @p3x-robot this is still occuring for you on 8.5? Do you have a minimal test case?

  7. p3x-robot commented on Sep 23, 2017

    @p3x-robot

    Yes it is still error:

    Updating 4d3e58a..532812e
    Fast-forward
     package.json | 2 +-
     yarn.lock    | 6 +++---
     2 files changed, 4 insertions(+), 4 deletions(-)
    
    
     9878 root      1192 S    grep fail2ban
    
    
    WAN DNS: 192.168.78.20 74.82.42.42 8.8.8.8
    
    
    /opt/router-scripts-lede/settings/common/override/
    /opt/router-scripts-lede/settings/d-link.router/override/
    
    
    
    
    
    
    
    
    
    module.js:473
          throw err;
          ^
    
    TypeError: assertEncoding is not a function
        at getOptions (fs.js:81:5)
        at Object.realpathSync (fs.js:1584:15)
        at toRealPath (module.js:154:13)
        at Function.Module._findPath (module.js:203:22)
        at Function.Module._resolveFilename (module.js:525:25)
        at Function.Module._load (module.js:453:25)
        at Function.Module.runMain (module.js:665:10)
        at startup (bootstrap_node.js:201:16)
        at bootstrap_node.js:626:3
    
    
    */5	* * * *   /opt/router-scripts-lede/update-domains >>/var/log/update-domains.log 2>>/var/log/update-domains.error.log
    10 3 * * *      /opt/router-scripts-lede/daily >>/var/log/daily.log 2>>/var/log/daily.error.log
    8 4 * * *       /opt/router-scripts-lede/backup-daily >>/var/log/backup-daily.log 2>>/var/log/backup-daily.error.log
    6 5 * * 0       /opt/router-scripts-lede/backup-weekly >>/var/log/backup-weekly.log 2>>/var/log/backup-weekly.error.log
    5 6 1 * *       /opt/router-scripts-lede/backup-monthly >>/var/log/backup-monthly.log 2>>/var/log/backup-monthly.error.log
    9 * * * *      /opt/router-scripts-lede/cron-fail2ban-check  >>/var/log/fail2ban-check.log 2>>/var/log/fail2ban-check.error.log
    
  8. p3x-robot commented on Sep 23, 2017

    @p3x-robot

    this is my error.

  9. 12 remaining items

  10. added a commit that references this issue on May 10, 2018
  11. added a commit that references this issue on May 12, 2018
  12. gireeshpunathil commented on May 14, 2018

    @gireeshpunathil
    Member

    this is fixed in the latest, and a regression test is added now through #20391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions