[英]How do I run a JavaScript project with no package.json file present, which therefore gives error when running it?
I am trying to run this project.我正在尝试运行 这个项目。 It has no
package.json
file in it.它没有
package.json
文件。 Being an absolute noob with JS, with no JS experience whatsoever, I searched online how to run JS projects.作为 JS 的绝对菜鸟,没有任何 JS 经验,我在网上搜索了如何运行 JS 项目。 Every link I found seems to assume that the file
package.json
is present.我找到的每个链接似乎都假设文件
package.json
存在。 So, you typically do a "npm install" and then "npm start".因此,您通常先执行“npm install”,然后再执行“npm start”。 But since there's no "package.json" file present in this project, running "npm install" doesn't do anything.
但是由于该项目中不存在“package.json”文件,因此运行“npm install”不会执行任何操作。 But when I do "npm start", I get this error:
但是当我执行“npm start”时,我收到这个错误:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/username/Downloads/Face-Detection-JavaScript-master/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/username/Downloads/Face-Detection-JavaScript-master/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2020-08-26T04_51_15_254Z-debug.log
So, how do I run this project?那么,我该如何运行这个项目呢?
I tried the solutions given here and here , but to no avail.我尝试了此处和此处给出的解决方案,但无济于事。
I also tried node script.js
, but I get the following error:我也尝试过
node script.js
,但出现以下错误:
const video = document.getElementById('video')
^
ReferenceError: document is not defined
at Object.<anonymous> (/Users/username/Downloads/Face-Detection-JavaScript-master/script.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
When I open the index.html
file in browser, I just get a blank page:当我在浏览器中打开
index.html
文件时,我只得到一个空白页面:
This doesn't have anything to do with Node.js.这与 Node.js 没有任何关系。 All you have to do is open the HTML file in your browser.
您所要做的就是在浏览器中打开 HTML 文件。
This is if you want to run javascript with node
, for which you need to have node and npm installed, ( installation link here ), and initialize an node project with npm init --y
to generate a package.json这是如果你想用
node
运行 javascript,你需要安装 node 和 npm,(安装链接在这里),并使用npm init --y
初始化一个 node 项目以生成 package.json
But , in this case though, you just need to run the html file on your browser, and the javascript code will run on the browser, so you don't need to do all that.但是,在这种情况下,您只需要在浏览器上运行 html 文件,并且 javascript 代码将在浏览器上运行,因此您不需要做所有这些。
Only nodeJS projects need package.json
.只有 nodeJS 项目需要
package.json
。 You can run your javascript project by putting your index.html
or main file directly on browser您可以通过将
index.html
或主文件直接放在浏览器index.html
运行您的 javascript 项目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.