Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Next.js-网页包别名组件文件夹不';行不通_Javascript_Reactjs_Webpack_Next.js - Fatal编程技术网

Javascript Next.js-网页包别名组件文件夹不';行不通

Javascript Next.js-网页包别名组件文件夹不';行不通,javascript,reactjs,webpack,next.js,Javascript,Reactjs,Webpack,Next.js,我正在按照文档中的建议扩展next.js网页包配置 const path = require('path') module.exports = { webpack: (config, { dev }) => { config.resolve = { alias: { Templates: path.resolve(__dirname, 'templates/'), Components: path.resolve(__dirname

我正在按照文档中的建议扩展next.js网页包配置

const path = require('path')

module.exports = {
  webpack: (config, { dev }) => {
    config.resolve = {
      alias: {
        Templates: path.resolve(__dirname, 'templates/'),
        Components: path.resolve(__dirname, 'components/')
      }
    }
    return config
  }
}
我想让我的导入工作如下:

import Template from 'Templates/Base'
import Input from 'Components/Input'
.next
.storybook
components
|_ Header
|__ index.js
|_ Input
|__ index.js
templates
|_ Base
|__ index.js
pages
|_ index.js
node_modules
containers
stories
...
由于出现以下错误,我在配置中犯了哪些错误:

找不到模块“组件/标题”

我的目录结构如下:

import Template from 'Templates/Base'
import Input from 'Components/Input'
.next
.storybook
components
|_ Header
|__ index.js
|_ Input
|__ index.js
templates
|_ Base
|__ index.js
pages
|_ index.js
node_modules
containers
stories
...

需要创建包含以下内容的
.babelrc
文件,而不是编辑网页包文件:

{
  "plugins": [
    ["module-alias", [
      { "src": "./components", "expose": "Components" },
      { "src": "./containers", "expose": "Containers" },
      { "src": "./templates", "expose": "Templates" }
    ]]
  ],
  "presets": [
    "es2015",
    "next/babel"
  ]
}

通过这种方式,我们扩展了Next.js.babelrc配置,它在服务器端也运行良好

您是否尝试过指定正在搜索当前文件夹,例如:Templates:path.resolve(_dirname,“./Templates/”)?@SimeonSimeonoff是的,同样的问题。