安装 laravel/vite 应用程序时出现错误“找不到模块‘node:path’”

安装 laravel/vite 应用程序时出现错误“找不到模块‘node:path’”

我尝试在远程主机上的 Ubuntu 18.04 上安装 laravel9/vite 应用程序并出现错误:

root@nsn-do-lamp:/var/www/html/mng-products# npm -v
6.14.8
root@nsn-do-lamp:/var/www/html/mng-products# npm run  build

> @ build /var/www/html/mng-products
> vite build

failed to load config from /var/www/html/mng-products/vite.config.js
error during build:
Error: Cannot find module 'node:path'
Require stack:
- /var/www/html/mng-products/node_modules/vite/dist/node-cjs/publicUtils.cjs
- /var/www/html/mng-products/node_modules/vite/index.cjs
- /var/www/html/mng-products/vite.config.js
- /var/www/html/mng-products/node_modules/vite/dist/node/chunks/dep-74663fff.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/var/www/html/mng-products/node_modules/vite/dist/node-cjs/publicUtils.cjs:5:14)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object._require.extensions.<computed> [as .js] (file:///var/www/html/mng-products/node_modules/vite/dist/node/chunks/dep-74663fff.js:63058:17)
        at Module.load (internal/modules/cjs/loader.js:928:32)
        at Function.Module._load (internal/modules/cjs/loader.js:769:14)
        npm ERR! code ELIFECYCLE
        npm ERR! errno 1
        npm ERR! @ build: `vite build`
        npm ERR! Exit status 1
        npm ERR!
        npm ERR! Failed at the @ build script.
        npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

        npm ERR! A complete log of this run can be found in:
        npm ERR!     /root/.npm/_logs/2022-09-21T11_26_59_040Z-debug.log


root@nsn-do-lamp:/var/www/html/mng-products# cat /var/www/html/mng-products/vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

        export default defineConfig({
        plugins: [
        laravel({
        input: [
        'resources/css/app.css',
        'resources/js/app.js',
        ],
        refresh: true,
        }),
        ],
        });

root@nsn-do-lamp:/var/www/html/mng-products# node -v
        v14.15.1

root@nsn-do-lamp:/var/www/html/mng-products# whereis node
        node: /usr/bin/node /usr/local/bin/node /usr/include/node /usr/share/man/man1/node.1.gz

root@nsn-do-lamp:/var/www/html/mng-products# lsb_release -d; uname -r; uname -i
        Description:    Ubuntu 18.04.5 LTS
        4.15.0-192-generic
        x86_64

    

有什么想法可以解决这个问题吗?

我的操作系统:

root@nsn-do-lamp:/var/www/html/mng-products# uname -a
Linux nsn-do-lamp 4.15.0-192-generic #203-Ubuntu SMP Wed Aug 10 17:40:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
root@nsn-do-lamp:/var/www/html/mng-products# 
root@nsn-do-lamp:/var/www/html/mng-products# lsb_release -d; uname -r; uname -i
Description:    Ubuntu 18.04.5 LTS
4.15.0-192-generic

谢谢!

答案1

node -v给你什麼了?

我遇到了同样的错误 - 由于节点版本太旧(v14.17.3),而目前的稳定版本是 v18.12.1

我通过从下载最新的稳定版本解决了我的问题https://nodejs.org/en/download/

相关内容