在Next.js应用程序中导入外部Typescript文件

3

我有一个使用Typescript文件构建的Next.js应用程序A,以及一个名为B的包,该包包含以下index.tsx文件:

export default () => {
    console.log('hi');
}

当我通过以下方式在Next.js应用程序A的任何文件中导入它时:
import f from 'B';

我遇到了这个错误:

ModuleParseError: Module parse failed: Unexpected token (15:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

这似乎与Webpack有关,但我不知道如何解决它。


我也遇到了同样的困难。你找到解决办法了吗? - Marten Veldthuis
我在他们的存储库中开了一个问题:https://github.com/zeit/next.js/issues/9303。这似乎是一个已知的问题。 - Lucas Willems
相关 https://dev59.com/9FIG5IYBdhLWcg3wqTRF - Aleksandr Smyshliaev
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接