简体   繁体   English

如何在 Linux Mint 本地服务我的 javascript 应用程序

[英]How do I serve my javascript app locally on Linux Mint

I'm currently following a tutorial, and I've made sure to follow each and every step.我目前正在学习教程,并且确保遵循每一步。 I'm trying to locally host my javascript app at localhost:3000.我正在尝试在 localhost:3000 本地托管我的 javascript 应用程序。 However, I'm unable to do so, and whenever I try to run npm run dev I get the following error log:但是,我无法这样做,每当我尝试运行npm run dev时,我都会收到以下错误日志:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm@6.14.4
3 info using node@v10.19.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle personalwebsite@0.0.0~predev: personalwebsite@0.0.0
6 info lifecycle personalwebsite@0.0.0~dev: personalwebsite@0.0.0
7 verbose lifecycle personalwebsite@0.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle personalwebsite@0.0.0~dev: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 verbose lifecycle personalwebsite@0.0.0~dev: CWD: /home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite
10 silly lifecycle personalwebsite@0.0.0~dev: Args: [ '-c', 'vite' ]
11 silly lifecycle personalwebsite@0.0.0~dev: Returned: code: 1  signal: null
12 info lifecycle personalwebsite@0.0.0~dev: Failed to exec dev script
13 verbose stack Error: personalwebsite@0.0.0 dev: `vite`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid personalwebsite@0.0.0
15 verbose cwd /home/omar-backup/Desktop/MrBoogle.github.io/personalWebsite
16 verbose Linux 5.4.0-26-generic
17 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "dev"
18 verbose node v10.19.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error personalwebsite@0.0.0 dev: `vite`
22 error Exit status 1
23 error Failed at the personalwebsite@0.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I've spent about an hour now trying to figure this out but have yet to find anything.我已经花了大约一个小时试图弄清楚这一点,但还没有找到任何东西。 I installed vite but nothing gets hosted (I'm trying to host my app on localhost:3000) and instead a weird window pops up using qt5ct.我安装了 vite 但没有托管(我试图在 localhost:3000 上托管我的应用程序),而是使用 qt5ct 弹出一个奇怪的 window。 Unfortunately that no longer works because I probably messed something up while trying to get this to work.不幸的是,这不再有效,因为我可能在试图让它工作时搞砸了。 The tutorial I'm following can be found here .我正在关注的教程可以在这里找到。 I'm running into issues around the 2:45 mark.我在2:45左右遇到问题。

When you create a project with npm init, like on the tutorial you've seen, a project from a template with be created at some directory.当您使用 npm init 创建项目时,就像您在教程中看到的那样,在某个目录中创建来自模板的项目。 On your case, you ran:在你的情况下,你跑了:

npm init @vitejs/app

This command got you a folder with some predefined template of Node.JS, which created a package.json for you, wich have all the dependencies required for that project to being able to work.此命令为您提供了一个包含一些预定义的 Node.JS 模板的文件夹,该模板为您创建了 package.json,它具有该项目能够工作所需的所有依赖项。 At your case, for example:在您的情况下,例如:

{
  "name": "vite-project",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  "devDependencies": {
    "vite": "^2.3.3"
  }
}

As you can see, there is a devDependency call vite , which need to be installed to execute the npm script of dev, which translates to "dev": "vite" .可以看到,有一个 devDependency 调用vite ,需要安装它来执行 dev 的 npm 脚本,翻译为"dev": "vite"

When you ran before, the vite dependencie wasnt installed on the project, and that was the reason of the error:之前运行时,项目中没有安装vite依赖,这就是错误的原因:

error personalwebsite@0.0.0 dev: `vite`

When you run npm install, it installed all the required dependencies of package.json.当您运行 npm 安装时,它安装了 package.json 所需的所有依赖项。 So after you installed the vite dependency with npm install (which will take the package.json definition), it stopped lacking dependencies.因此,在您使用 npm install 安装 vite 依赖项后(将采用 package.json 定义),它不再缺少依赖项。

That is why your error change to:这就是为什么您的错误更改为:

 Cannot find module 'worker_threads' 

This is other error , and is probably because you are using and old version of node (info using node@v10.19.0).这是另一个错误,可能是因为您使用的是旧版本的节点(使用 node@v10.19.0 的信息)。 Trying to replicate I encounter the same problem:尝试复制我遇到了同样的问题: 节点 10

But when I update to a newer version (Node 14), it didn't happend.但是当我更新到较新的版本(节点 14)时,它并没有发生。 So, just update your node version所以,只需更新您的节点版本

节点 14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM