如何修复"You may need an appropriate loader to handle this file type, currently no loaders are configure



我使用next.js。导出文件索引中的类型时。在第三方包中出现错误。

Module parse failed: Unexpected token (23:7)
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
> export type { Validate } from './src/nullable'

in package。Json,假设添加了以下依赖项

"@yourproject/your-project":"文件:. ./your-project",

then in next。添加transpilePackages: ['@yourproject/your-project'],这允许加载器直接处理.ts文件。

transpilePackages: ['@yourproject/your-project'],
webpack: (config) => {
config.resolve.extensionAlias = {
".js": [".ts", ".tsx", ".js", ".jsx"],
".mjs": [".mts", ".mjs"],
".cjs": [".cts", ".cjs"],
};
return config;
},

当您的配置比您想要使用的配置少时,就会出现这个问题。

在你的例子中,你试图在你的NextJS项目中使用Typescript。不幸的是,你的Webpack配置中没有Typescript文件加载器。

有两种方法可以解决这个问题:

  • 使用NextJS Typescript项目从这里开始的例子
  • 在Webpack配置中添加TS文件加载器(此处参考)

相关内容

最新更新