Next JS Babel无法解析'module'

yk9xbfzb  于 2022-12-16  发布在  Babel
关注(0)|答案(2)|浏览(179)

我已经开始用Next JS和Lingui.js开发一个多语言的Web应用程序,Lingui.js使用的是babel,所以我也必须安装它。
我已经学习了这个教程https://blog.logrocket.com/complete-guide-internationalization-nextjs/在遇到一些问题之后,我还学习了Lingui.js的官方文档https://lingui.js.org/tutorials/setup-react.html
我遇到了很多问题与巴别塔和 typescript 。但现在我挣扎与以下错误,我找不到任何帮助:

wait  - compiling / (client and server)...
error - ./node_modules/resolve-from/index.js:3:0
Module not found: Can't resolve 'module'

Import trace for requested module:
./node_modules/import-fresh/index.js
./node_modules/cosmiconfig/dist/loaders.js
./node_modules/cosmiconfig/dist/index.js
./node_modules/babel-plugin-macros/dist/index.js
./node_modules/@lingui/macro/index.js
./src/pages/index.tsx

https://nextjs.org/docs/messages/module-not-found
false
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
    at Home (webpack-internal:///./src/pages/index.tsx:36:51)
    at I18nProvider (C:\Project\app\node_modules\@lingui\react\cjs\react.development.js:46:19)
    at MyApp (webpack-internal:///./src/pages/_app.tsx:48:24)
    at StyleRegistry (C:\Project\app\node_modules\styled-jsx\dist\index\index.js:671:34)
    at AppContainer (C:\Project\app\node_modules\next\dist\server\render.js:394:29)
    at AppContainerWithIsomorphicFiberStructure (C:\Project\app\node_modules\next\dist\server\render.js:424:57)
    at div
    at Body (C:\Project\app\node_modules\next\dist\server\render.js:701:21)
error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, 
or you might have mixed up default and named imports.

这里是我的babel.config.js

module.exports = {
    presets: [
        "@babel/preset-env",
        "@babel/preset-react",
        "@babel/preset-typescript"
    ],
    plugins: [
        ["@babel/plugin-transform-runtime",
            {
                "regenerator": true
            }
        ],
        [
            "@babel/plugin-transform-react-jsx",
            {
                "runtime": "automatic"
            }
        ],
        [
            '@babel/plugin-transform-runtime',
            {
                absoluteRuntime: false,
                corejs: false,
                helpers: true,
                regenerator: true,
                version: '7.0.0-beta.0',
            },
            'react-native-reanimated/plugin',
        ],
    ]
}

和我的webpack.config.js

module.exports = {
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                exclude: /node_modules/,
                use: ['babel-loader', 'ts-loader']
            }
        ]
    }
};

带有React.jsx的部分:由于index.tsx中存在getStaticProps,因此类型无效。
所以这可能是另一个问题

hc8w905p

hc8w905p1#

你已经试过这里提到的解决方案了吗?

  • 网络包配置js*
node: {
 module: "empty",
 }
rvpgvaaj

rvpgvaaj2#

我最终删除了Babel和Lingui中的所有内容,并从另一个正在运行的项目中复制了所有导入内容。
说不出它们之间的区别,但后来它起作用了。

相关问题