NodeJS 您访问的页面不存在,ENOENT:没有这样的文件或目录,uv_cwd

nc1teljy  于 2023-01-01  发布在  Node.js
关注(0)|答案(5)|浏览(102)

我按照Webpack指南运行npm run build时遇到了以下错误:

path.js:1086
          cwd = process.cwd();
                        ^

Error: ENOENT: no such file or directory, uv_cwd
    at Object.resolve (path.js:1086:25)
    at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:479:17)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:20)

我检查了所有的导入,一切看起来都很好。比我想象的应该是缓存问题,所以我运行npm cache clean -f令人惊讶的是,我得到了完全相同的错误。可能是NodeJS问题,但我不知道如何调试它。
下面是我的文件结构:

    • 包. json**
{
  "name": "test_webpack",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "clean-webpack-plugin": "^1.0.0",
    "css-loader": "^1.0.1",
    "csv-loader": "^3.0.2",
    "file-loader": "^2.0.0",
    "html-webpack-plugin": "^3.2.0",
    "style-loader": "^0.23.1",
    "webpack": "^4.25.1",
    "webpack-cli": "^3.1.2",
    "xml-loader": "^1.2.1"
  },
  "dependencies": {
    "lodash": "^4.17.11"
  }
}
    • 网络包配置js**
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: {
    app: './src/index.js',
    print: './src/print.js',
    sec: './src/secondClick.js'
  },
  devtool: 'inline-source-map',
  plugins: [
    new CleanWebpackPlugin(['dist']),
    new HtmlWebpackPlugin({
      titile: "Output manager from webpack n12"
    })
  ],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  }
};
c90pui9n

c90pui9n1#

关闭所有终端窗口并再次打开它对我很有效。
参考文献

6ojccjat

6ojccjat2#

看起来你的shell刚刚疯了:),只要cd.. && cd [the folder you tried running the command],一切都会恢复正常。

yhqotfr8

yhqotfr83#

重新启动电脑可能也会有所帮助。

rqcrx0a6

rqcrx0a64#

尝试在webpack.config中进行更改:

entry: {
    app: path.resolve(__dirname, 'src/index.js'),
    print: path.resolve(__dirname, 'src/print.js'),
    sec: path.resolve(__dirname, 'src/secondClick.js')
  },

并确保使用以下命令从项目根目录运行该命令:npx webpack --config webpack.config.js

klsxnrf1

klsxnrf15#

我得说错误很明显。

ENOENT: no such file or directory

因此,这将被解释为**'目录不正确或找不到您现在指向的目录。'**
在我的例子中,我在/test文件夹中,我应该切换到主项目文件夹,然后指示要运行哪个文件。

node specs/tests/config.js

我通过chdir('...')方法收到的错误,该错误不在/test文件夹中,而是在/project文件夹下。

相关问题