Sublime Forum

Pieces of JavaScript Code Not working

#1

I’m new to this, and downloaded Sublime to learn JavaScript. I’ve been working on learning from CodeAcademy.

I’m finding certain functions don’t work in Sublime. Any piece of code that requires a popup window (confirm, alert, prompt) give me an error in Sublime.

I already went and installed node.js on my Mac. The other functions (at least the ones I’ve learned thus far) work fine on Sublime, but I can’t get these things to work. I know the code is right because it worked on the editor provided by CodeAcademy. I copy and pasted into Sublime and I get the error. On Sublime 2, the error:

ReferenceError: prompt is not defined
at Object. (/Users/Danny/Library/Application Support/Sublime Text 2/Packages/User/test.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
[Finished in 0.4s with exit code 8]

I tried downloading Sublime 3 to see if that would make a difference, but I still get pretty much the same error:

/Users/Danny/Library/Application Support/Sublime Text 3/Packages/User/test.js:1
exports, require, module, __filename, __dirname) { var userChoice = prompt("Do
^
ReferenceError: prompt is not defined
at Object. (/Users/Danny/Library/Application Support/Sublime Text 3/Packages/User/test.js:1:80)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
[Finished in 0.1s with exit code 8]
[cmd: [’/usr/local/bin/node’, ‘/Users/Danny/Library/Application Support/Sublime Text 3/Packages/User/test.js’]]
[dir: /Users/Danny/Library/Application Support/Sublime Text 3/Packages/User]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

I’d really appreciate it if someone could help me out with this. I’ve been busting my brain looking for a fix all over the web, but I haven’t run into anything useful.

Thanks for your time.

0 Likes

#2

I found an explanation (though there is apparently no - simple - solution within Sublime itself) at this link - http://stackoverflow.com/questions/27415183/node-js-interpreter-for-sublime-text-issue

0 Likes

#3

Hopefully they figured that out after a year :roll_eyes: (topic is from 2015)
prompt is a function added by the browser. NodeJS is a different environment.
It has nothing to do with Sublime.

0 Likes