Skip to content

[Extension Bug] Atomic Data error after completing setup #599

Closed

Description

@joepio

Steps To Reproduce

  1. Install atomic extension
  2. Press continue on setup
  3. Error :(
ReferenceError: WebSocket is not defined

wr:index.js:9:45398

---
 6: `+I+c.join(`,
 7: `+I)+`
 8: `+i+"}":"{"+c.join(",")+"}",I=i,o}}Wt.exports=function(t,e,r){var n;if(I="",Ie="",typeof r=="number")for(n=0;n<r;n+=1)Ie+=" ";else typeof r=="string"&&(Ie=r);if(ie=e,e&&typeof e!="function"&&(typeof e!="object"||typeof e.length!="number"))throw new Error("JSON.stringify");return $e("",{"":t})}});var Gt=se(rt=>{rt.parse=Ft();rt.stringify=qt()});var Zt=se((Jn,Yt)=>{var Le=typeof JSON!="undefined"?JSON:Gt();Yt.exports=function(t,e){e||(e={}),typeof e=="function"&&(e={cmp:e});var r=e.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof e.cycles=="boolean"?e.cycles:!1,o=e.replacer||function(c,a){return a},s=e.cmp&&function(c){return function(a){return function(l,f){var p={key:l,value:a[l]},m={key:f,value:a[f]};return c(p,m)}}}(e.cmp),i=[];return function c(a,l,f,p){var m=r?`
 9: `+new Array(p+1).join(r):"",b=r?": ":":";if(f&&f.toJSON&&typeof f.toJS (VERY LONG)
10: 
11: `+r)}i()},[t]),t.error?t.error.message:n}async function Bn(t,e,r){let n=await r.getProperty(t),o=e.toString();switch(n.datatype){case"https://atomicdata.dev/datatypes/atomicURL":o=`[${e}](${e})`;break;case"https://atomicdata.dev/datatypes/resourceArray":o="",X(e).map(s=>{o=o+`[${s}](${s}),`});break;case"https://atomicdata.dev/datatypes/timestamp":o=ut(e).toLocaleString();break}return`
12: 
---

At.setWebSocket:index.js:9:48511
At.setServerUrl:index.js:9:48427
At:index.js:9:45790
Object.<anonymous>:index.js:13:628
Module._compile:loader:1101:14
Object.Module._extensions..js:loader:1153:10
Module.load:loader:981:32
Function.Module._load:loader:822:12
Module.require:loader:1005:19

I think I know how to fix it: conditional websocket support in @tomic/lib

Activity

  1. added
    bug
    extension
    on Jan 4, 2022
  2. joepio commented on Jan 4, 2022

    @joepio
    ContributorAuthor

    It seems to work just fine locally with yarn dev, didn't see an error.

    Two possible reasons:

    • Errors in production are handled differently then in development
    • WebSockets aren't available in production, but they are in development
  3. added a commit that references this issue on Jan 5, 2022
  4. joepio commented on Jan 5, 2022

    @joepio
    ContributorAuthor

    After my PR has been merged, my issue continues to happen. I've waited a couple of hours after the updated version was published, I've uninstalled the extension, but it seems my bug isn't fixed. This could happen because my fix wasn't good, or because I'm somehow still running the older version.

    The biggest hurdle for me to fixing this, is that the problem does not happen while running npm run dev. Could the dev version / runtime differ significantly? Could it be that some runtime errors are hidden for me during development? Or could it be that WebSockets is only available in development?

    @mathieudutour could you perhaps help me with this?

  5. mathieudutour commented on Jan 5, 2022

    @mathieudutour
    Member

    you could try with npm run build which will build the prod version, but yeah WebSocket isn't a NodeJS global so it's expected that it's not available.

    Keep in mind that the extensions are running in a NodeJS process and not in a browser

  6. joepio commented on Jan 5, 2022

    @joepio
    ContributorAuthor

    @mathieudutour

    you could try with npm run build which will build the prod version, but yeah WebSocket isn't a NodeJS global so it's expected that it's not available. Keep in mind that the extensions are running in a NodeJS process and not in a browser

    It makes sense that it's not available, I understand it's running in Node, but it's kind of weird that it doesn't crash in npm run dev mode, right? Is WebSocket available in dev mode, or is the error somehow handled and hidden? It's not appearing in the logs, or popping up.

    I ran npm run build, which succeeded, but I don't know where the built version is stored (can't find a dist or .js anywhere after running build).

  7. mathieudutour commented on Jan 5, 2022

    @mathieudutour
    Member

    Ah indeed, I found what's happening. WebSocket and window are indeed available in dev mode because react-dev-tools requires them. I'm going to add a warning whenever those global are accessed so that people will know it'll break in prod.

    So to fix it, you can do something like this:

    const customGlobal = global as any;
    customGlobal.WebSocket = require("ws");

    and add a dependency on ws.

    Also, in order to test with the "prod" environment, you can go to the Raycast preferences > Advanced > Use Node production environment.

    Sorry for the confusion

  8. joepio commented on Jan 5, 2022

    @joepio
    ContributorAuthor

    Thanks for the help and explanation! Turning on the Node Production environment setting makes the error appear, which helps me fix the issue.

  9. mathieudutour commented on Jan 6, 2022

    @mathieudutour
    Member

    Let me know when it's ready to go :)

  10. joepio commented on Jan 6, 2022

    @joepio
    ContributorAuthor

    It's ready to go @mathieudutour!

    Thanks!

  11. added a commit that references this issue on Jan 6, 2022
  12. joepio commented on Jan 6, 2022

    @joepio
    ContributorAuthor

    It's working!

  13. added a commit that references this issue on Sep 14, 2026
  14. added a commit that references this issue on Nov 12, 2026
  15. added a commit that references this issue on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugextension

    Type

    No type

    Fields

    Priority

    None yet

    Severity

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions