首页 > 解决方案 > 模块解析失败:意外字符 '�' (1:0) NEXTJS NESTJS

问题描述

我从 webpack 收到这个错误。我已经在https://github.com/thisismydesign/nestjs-starter复制了这个项目,当我尝试从我的资产文件夹中导入图像时,出现以下错误。通常,这些东西开箱即用。可能会发生什么?

提前致谢。

./assets/img/logo.png
Module parse failed: Unexpected character '�' (1:0)
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
(Source code omitted for this binary file)

我的配置如下:

文件夹结构

src
-client
--assets
--pages
--next.env.d.ts
--next.config.js
--tsconfig.json 
...
-server
-...

下一个.env.d.ts

/// <reference types="next" />
/// <reference types="next/types/global" />

declare module '*.png' {
  const value: any;
  export default value;
}

next.config.js

module.exports = {
  distDir: '../../.next',
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
            },
          },
        ],
      },
    ],
  },
};

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "next.config.js",
    "app",
    "pages",
    "components",
    "assets",
    "store"
  ],
  "exclude": ["node_modules"]
}

标签: typescriptwebpacknext.jsnestjs

解决方案


推荐阅读