简体   繁体   English

将样式指南添加到 next.js(反应)返回错误:ENOENT:没有这样的文件或目录,

[英]Adding style guide to next.js (react) returns Error: ENOENT: no such file or directory,

I just started learning next.js and I wanted to add some documentation using https://react-styleguidist.js.org/我刚开始学习 next.js,我想使用https://react-styleguidist.js.org/添加一些文档

I created my project using npx create-next-app我使用 npx create-next-app 创建了我的项目

After installing it, and adding some configuration安装后,并添加一些配置

[styleguide.config.js]
const path = require('path')

module.exports = {
    components: './**/*.js',
    webpackConfig: {
        entry: 'next/lib/app.js',
    module: {
        rules: [
            {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: "babel-loader",
                options: {
                    presets: ['@babel/react' ],
                    plugins: ['@babel/plugin-proposal-class-properties']
                }
            }

            },
            {
                test: /\.scss$/,
                loader: 'sass-loader'
            }
        ]
    }
    }
};

I'm getting the following error when trying to run it using the following command: npx styleguidist server尝试使用以下命令运行它时出现以下错误:npx styleguidist server

./node_modules/react-styleguidist/lib/client/index.js (./node_modules/react-styleguidist/lib/loaders/styleguide-loader.js!./node_modules/react-styleguidist/lib/client/index.js)
Error: ENOENT: no such file or directory, scandir '${projectPath}\node_modules\ally.md\amd'
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)
 @ ./node_modules/react-styleguidist/lib/client/index.js 36:19-71 46:2-49:4 46:65-49:3
 @ multi ./node_modules/react-styleguidist/lib/client/index ./node_modules/react-dev-utils/webpackHotDevClient.js

(Note that I have replaced the project path for "${projectPath}") (请注意,我已将项目路径替换为“${projectPath}”)

And I'm at a loss on how to fix it.我不知道如何解决它。

For further details, you can find my package.json here https://pastebin.com/H7RfxxKZ .有关更多详细信息,您可以在此处找到我的 package.json https://pastebin.com/H7RfxxKZ

My folder structure shown in below image:我的文件夹结构如下图所示: 在此处输入图像描述

  • All my components are under src/components, some include component.module.css files我所有的组件都在 src/components 下,其中一些包含 component.module.css 文件
  • My context components are under src/context我的上下文组件在 src/context
  • All my global scss can be found under "styles/"我所有的全局 scss 都可以在“styles/”下找到

Any guidance on why this can happen and how to solve it would be appreciated, my knowledge on how the configuration files work is limited, and any reference to any related article would be appreciated.任何关于为什么会发生这种情况以及如何解决它的指导将不胜感激,我对配置文件如何工作的了解有限,并且对任何相关文章的任何参考都将不胜感激。

Thanks for your help.谢谢你的帮助。 have a nice rest of the day and stay safe.有一个不错的 rest 并保持安全。

After doing some further testing, I found out that my main problem was the "components: './**/*.js'" and the fact that I was missing some alias for my components.在做了一些进一步的测试之后,我发现我的主要问题是“组件:'./**/*.js'”以及我缺少组件的一些别名的事实。 I will post here what worked for me.我会在这里发布对我有用的东西。

 module.exports = {
    
  components: "./src/**/*.js",
  skipComponentsWithoutExample: true, //You don't need this one
  moduleAliases: { //Map it to your folder structure 
    'components': path.resolve(__dirname, 'src','components'),
    '_db': path.resolve(__dirname, 'src','_db'),
    'context': path.resolve(__dirname, 'src','context'),
    'styles': path.resolve(__dirname, 'src','styles'),
  },
  webpackConfig: {
    module: {
      rules: [
        {
          test: /\.js?$/,
          exclude: /node_modules/,
          loader: "babel-loader",
        },
        {
            test: /\.scss$/,
            loaders: [
                'style-loader',
                'css-loader',
                'sass-loader'
            ]
        },
        { //This code prevents errors with font-awesome
            test: /\.(ttf|eot|svg|gif|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            use: [{
                loader: 'file-loader',
            }]
        },
      ],
    },
  },
};

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

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