简体   繁体   English

如何在没有 package.json 文件的情况下运行 JavaScript 项目,从而在运行时出错?

[英]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.

相关问题 如何在package.json中运行nodejs项目 - How to run nodejs project in package.json 如何向运行 javascript 文件的 package.json 文件添加自定义脚本? - How do I add a custom script to my package.json file that runs a javascript file? 如何配置 package.json 以运行以相似名称结尾的测试用例文件? - How to configure package.json to run test case file which ends with similar names? 尝试在 package.json 中运行 CSS 构建时出错 - Error when trying to run CSS build in package.json 如何在package.json文件中指定项目npm注册表 - How to specify project npm registry inside package.json file 如何在 package.json 脚本中运行多个命令? - How can I run multiple commands in package.json scripts? 当新安装的模块没有出现在 package.json “依赖项”列表中时,如何在 React 中使用它们? - How do I use newly installed modules in React when they do not appear in the package.json "dependencies" list? 如何在dist目录中生成单独的package.json文件? - How do I generate a separate package.json file in the dist directory? 如何将 package.json 与单独的文件(在本例中为 nodemon.app)链接 - How do I link package.json with a separate file (in this case nodemon.app) 如何自动更新 package.json 中的条目? - How do I update the entries in package.json automatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM