weixin_39709674
weixin_39709674
2021-01-09 08:07

1.4.0 broken in node.js

Looks like somehow a dependency on 'window' snuck in.

~/tmp/fp $ npm install firepad.4.0 firepad.4.0 node_modules/firepad ├── jsdom.2.1 (acorn-globals.0.9, webidl-conversions.0.1, array-equal.0.0, sax.2.1, abab.0.3, xml-name-validator.0.1, symbol-tree.1.4, tough-cookie.2.2, nwmatcher.3.8, cssom.3.1, iconv-lite.4.13, parse5.5.1, acorn.7.0, whatwg-url.0.0, escodegen.8.0, request.72.0, cssstyle.2.36) └── firebase.0.5 (rsvp.2.1, faye-websocket.9.3, jsonwebtoken.7.0)

~/tmp/fp $ node -e "require('firepad')" /Users/mikelehen/tmp/fp/node_modules/firepad/dist/firepad.min.js:13 !function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=b():"function"==typeof c.define&&c.define.amd?define(b):c[a]=b()}("Firepad",function(){var a=a||{};a.utils={},a.utils.makeEventEmitter=function(a,b){a.prototype.allowedEvents_=b,a.prototype.on=function(a,b,c){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{},this.eventListeners_[a]=this.eventListeners_[a]||[],this.eventListeners_[a].push({callback:b,context:c})},a.prototype.off=function(a,b){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{};for(var c=this.eventListeners_[a]||[],d=0;d<c.length;d++)if(c[d].callback===b)return void c.splice(d,1)},a.prototype.trigger=function(a){this.eventListeners_=this.eventListeners_||{};for(var b=this.eventListeners_[a]||[],c=0;c<b.length;c++)b[c].callback.apply(b[c].context,Array.prototype.slice.call(arguments,1))},a.prototype.validateEventType_=function(a){if(this.allowedEvents_){for(va

ReferenceError: window is not defined at /Users/mikelehen/tmp/fp/node_modules/firepad/dist/firepad.min.js:13:17964 at /Users/mikelehen/tmp/fp/node_modules/firepad/dist/firepad.min.js:13:23320 at a (/Users/mikelehen/tmp/fp/node_modules/firepad/dist/firepad.min.js:13:76) at Object. (/Users/mikelehen/tmp/fp/node_modules/firepad/dist/firepad.min.js:13:141) at Module._compile (module.js:435:26) at Object.Module._extensions..js (module.js:442:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Module.require (module.js:366:17) at require (module.js:385:17)

该提问来源于开源项目:FirebaseExtended/firepad

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

10条回答

  • weixin_39684967 weixin_39684967 4月前

    Is this fix actually incorporated in firepad at all? I'm trying to deploy an app to heroku after migrating everything to the latest firebase API and I see that v1.4.0 breaks for me on heroku:

    
    2017-02-17T05:41:20.718775+00:00 heroku[web.1]: State changed from crashed to starting
    2017-02-17T05:41:20.244955+00:00 app[api]: Deploy ce49dec by user <.....>
    2017-02-17T05:41:20.244955+00:00 app[api]: Running release v46 commands by user kratsg.com
    2017-02-17T05:41:20.674964+00:00 app[api]: Release v46 created by user <.....>
    2017-02-17T05:41:26.807124+00:00 heroku[web.1]: Starting process with command `npm start`
    2017-02-17T05:41:30.179530+00:00 app[web.1]: 
    2017-02-17T05:41:30.179556+00:00 app[web.1]: > <.....> start /app
    2017-02-17T05:41:30.179557+00:00 app[web.1]: > node ./bin/www
    2017-02-17T05:41:30.179558+00:00 app[web.1]: 
    2017-02-17T05:41:30.575552+00:00 app[web.1]: /app/node_modules/firepad/dist/firepad.min.js:13
    2017-02-17T05:41:30.575573+00:00 app[web.1]: !function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=b():"function"==typeof c.define&&c.define.amd?define(b):c[a]=b()}("Firepad",function(){var a=a||{};a.utils={},a.utils.makeEventEmitter=function(a,b){a.prototype.allowedEvents_=b,a.prototype.on=function(a,b,c){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{},this.eventListeners_[a]=this.eventListeners_[a]||[],this.eventListeners_[a].push({callback:b,context:c})},a.prototype.off=function(a,b){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{};for(var c=this.eventListeners_[a]||[],d=0;d<c.length void c.splice b="this.eventListeners_[a]||[],c=0;c<b.length;c++)b[c].callback.apply(b[c].context,Array.prototype.slice.call(arguments,1))},a.prototype.validateEventType_=function(a){if(this.allowedEvents_){for(var" app referenceerror: window is not defined at a object.> (/app/node_modules/firepad/dist/firepad.min.js:13:141)
    2017-02-17T05:41:30.575584+00:00 app[web.1]:     at Module._compile (module.js:413:34)
    2017-02-17T05:41:30.575585+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:422:10)
    2017-02-17T05:41:30.575586+00:00 app[web.1]:     at Module.load (module.js:357:32)
    2017-02-17T05:41:30.575586+00:00 app[web.1]:     at Function.Module._load (module.js:314:12)
    2017-02-17T05:41:30.575587+00:00 app[web.1]:     at Module.require (module.js:367:17)
    2017-02-17T05:41:30.575587+00:00 app[web.1]:     at require (internal/module.js:16:19)
    2017-02-17T05:41:30.586288+00:00 app[web.1]: 
    2017-02-17T05:41:30.590525+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic
    2017-02-17T05:41:30.590841+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
    2017-02-17T05:41:30.591032+00:00 app[web.1]: npm ERR! node v5.5.0
    2017-02-17T05:41:30.591401+00:00 app[web.1]: npm ERR! npm  v3.3.12
    2017-02-17T05:41:30.591677+00:00 app[web.1]: npm ERR! code ELIFECYCLE
    2017-02-17T05:41:30.591856+00:00 app[web.1]: npm ERR! captionator.0.0 start: `node ./bin/www`
    2017-02-17T05:41:30.592020+00:00 app[web.1]: npm ERR! Exit status 1
    2017-02-17T05:41:30.592208+00:00 app[web.1]: npm ERR! 
    2017-02-17T05:41:30.592377+00:00 app[web.1]: npm ERR! Failed at the captionator.0.0 start script 'node ./bin/www'.
    2017-02-17T05:41:30.592548+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
    2017-02-17T05:41:30.592710+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the captionator package,
    2017-02-17T05:41:30.592875+00:00 app[web.1]: npm ERR! not with npm itself.
    2017-02-17T05:41:30.593036+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
    2017-02-17T05:41:30.593190+00:00 app[web.1]: npm ERR!     node ./bin/www
    2017-02-17T05:41:30.594363+00:00 app[web.1]: npm ERR! You can get their info via:
    2017-02-17T05:41:30.594568+00:00 app[web.1]: npm ERR!     npm owner ls captionator
    2017-02-17T05:41:30.594766+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
    2017-02-17T05:41:30.597760+00:00 app[web.1]: 
    2017-02-17T05:41:30.598015+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
    2017-02-17T05:41:30.598355+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
    2017-02-17T05:41:30.675773+00:00 heroku[web.1]: State changed from starting to crashed
    2017-02-17T05:41:30.661213+00:00 heroku[web.1]: Process exited with status 1
    </c.length></.....></.....></.....>

    and indeed, if I run this locally, I get

    
    Lord Stark:~/captionator (heroku)$ node -e "require('firepad')"
    /Users/kratsg/captionator/node_modules/firepad/dist/firepad.min.js:13
    !function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=b():"function"==typeof c.define&&c.define.amd?define(b):c[a]=b()}("Firepad",function(){var a=a||{};a.utils={},a.utils.makeEventEmitter=function(a,b){a.prototype.allowedEvents_=b,a.prototype.on=function(a,b,c){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{},this.eventListeners_[a]=this.eventListeners_[a]||[],this.eventListeners_[a].push({callback:b,context:c})},a.prototype.off=function(a,b){this.validateEventType_(a),this.eventListeners_=this.eventListeners_||{};for(var c=this.eventListeners_[a]||[],d=0;d<c.length void c.splice b="this.eventListeners_[a]||[],c=0;c<b.length;c++)b[c].callback.apply(b[c].context,Array.prototype.slice.call(arguments,1))},a.prototype.validateEventType_=function(a){if(this.allowedEvents_){for(" referenceerror: window is not defined at a object.> (/Users/kratsg/captionator/node_modules/firepad/dist/firepad.min.js:13:141)
        at Module._compile (module.js:413:34)
        at Object.Module._extensions..js (module.js:422:10)
        at Module.load (module.js:357:32)
        at Function.Module._load (module.js:314:12)
        at Module.require (module.js:367:17)
        at require (internal/module.js:16:19)
    </c.length>

    My guess is one needs to specify the github URL in the meantime as I see no new tags/releases since May 2016.

    点赞 评论 复制链接分享
  • weixin_39599097 weixin_39599097 4月前

    Yup, I don't believe a new version has been released with the fix even though my PR was merged a while back.

    Note that if you point to a github url, it must be one that contains the built version within the dist folder. There is a built branch on my fork that includes the built version which you can point to, or do something similar on your own fork.

    点赞 评论 复制链接分享
  • weixin_39684967 weixin_39684967 4月前

    Yeah, I just went ahead and made https://github.com/kratsg/firepad/tree/build which contains the grunt build output. I was looking at the firepad releases and it seems they only do a minor release, rather than patch releases. Thanks!

    点赞 评论 复制链接分享
  • weixin_39625987 weixin_39625987 4月前

    A workaround till the available npm version (1.4.0) gets the patch is to define window: global.window={}; const Firepad = require('firepad');

    点赞 评论 复制链接分享
  • weixin_39854923 weixin_39854923 4月前

    I was able to get it to work by replacing all instances of window with global. Is this a valid solution?

    点赞 评论 复制链接分享
  • weixin_39709674 weixin_39709674 4月前

    Yep! That's exactly what I was going to try. If you feel like sending a pull request, that'd be great. :-) Else, I'll get to it when I'm next working on firepad.

    点赞 评论 复制链接分享
  • weixin_39620535 weixin_39620535 4月前

    I am using firebase 2.4.2 and firepad 1.4.0

    After changing all instances of window to global and minifying file, I am getting following error:

    /test/learning/firebase-test/node_modules/firepad/dist/firepad.min.js:13 !function(t,e,r){"undefined"!=typeof module&&module.exports?module.exports=e():"function"==typeof r.define&&r.define.amd?define(e):r[t]=e()}("Firepad",function(){var t=t||{};t.utils={},t.utils.makeEventEmitter=function(t,e){t.prototype.allowedEvents_=e,t.prototype.on=function(t,e,r){this.validateEventType_(t),this.eventListeners_=this.eventListeners_||{},this.eventListeners_[t]=this.eventListeners_[t]||[],this.eventListeners_[t].push({callback:e,context:r})},t.prototype.off=function(t,e){this.validateEventType_(t),this.eventListeners_=this.eventListeners_||{};for(var r=this.eventListeners_[t]||[],n=0;n<r.length;n++)if(r[n].callback===e)return void r.splice(n,1)},t.prototype.trigger=function(t){this.eventListeners_=this.eventListeners_||{};for(var e=this.eventListeners_[t]||[],r=0;r<e.length;r++)e[r].callback.apply(e[r].context,Array.prototype.slice.call(arguments,1))},t.prototype.validateEventType_=function(t){if(this.allowedEvent TypeError: Cannot read property 'firebase' of undefined at /test/learning/firebase-test/node_modules/firepad/dist/firepad.min.js:13:17965 at /test/learning/firebase-test/node_modules/firepad/dist/firepad.min.js:13:23315 at t (/test/learning/firebase-test/node_modules/firepad/dist/firepad.min.js:13:76) at Object. (/test/learning/firebase-test/node_modules/firepad/dist/firepad.min.js:13:141) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17)

    点赞 评论 复制链接分享
  • weixin_39599097 weixin_39599097 4月前

    +1 I am seeing this as well, causing me to not be able to use Headless.

    点赞 评论 复制链接分享
  • weixin_39709674 weixin_39709674 4月前

    Pull request welcome if somebody has time to dig into this...

    点赞 评论 复制链接分享
  • weixin_39599097 weixin_39599097 4月前

    Created this PR. All it took was a removing a reference to window.firebase (not sure why this was added).

    Using this code everything appears to be working on NodeJS and in Browser, but not sure if there is some unforeseen reason this code was needed.

    点赞 评论 复制链接分享

相关推荐