简体   繁体   English

您可能需要一个合适的加载器来处理这种文件类型。 ReactJs

[英]You may need an appropriate loader to handle this file type. ReactJs

I am getting this error while running a ReactJs App on the local system.在本地系统上运行 ReactJs 应用程序时出现此错误。 This app is used to build a chrome extension.此应用程序用于构建 chrome 扩展程序。

Error on terminal终端错误

../common/src/utils/index.ts 1:23
Module parse failed: Unexpected token (1:23)
You may need an appropriate loader to handle this file type.
> export const delay = (t: number) => new Promise((resolve) => setTimeout(resolve, t));
| 
| export const recurce = (f: Function, timeout: number) => setTimeout(() => f(), timeout);

Error on chrome console chrome 控制台上的错误

0.chunk.js:78512 ../common/src/utils/states.ts 4:7
Module parse failed: Unexpected token (4:7)
You may need an appropriate loader to handle this file type.
| const UsaStates = require('usa-states').UsaStates;
| 
> export interface IUSAState {
|   abbreviation: string;
|   name: string;
console.<computed> @ 0.chunk.js:78512

package.json包.json

{
  "name": "extention",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^3.9.2",
    "@types/jest": "24.0.7",
    "@types/node": "11.9.5",
    "@types/react": "16.8.5",
    "@types/react-dom": "16.8.2",
    "axios": "^0.18.0",
    "country-json": "^1.0.8",
    "jwt-decode": "^2.2.0",
    "react": "^16.8.3",
    "react-dom": "^16.8.3",
    "react-jss": "^8.6.1",
    "typeface-roboto": "0.0.54",
    "typescript": "3.3.3333",
    "usa-states": "0.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "node ./scripts/build-non-split.js",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "web:build": "env-cmd --use-shell 'web-ext build'",
    "preweb:build": "npm run build"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "@types/chrome": "0.0.86",
    "@types/jwt-decode": "^2.2.1",
    "@types/react-jss": "^8.6.3",
    "env-cmd": "^10.0.1",
    "react-scripts": "^2.1.5",
    "rewire": "^4.0.1",
    "web-ext": "^4.0.0"
  }
}

tsconfig.json配置文件

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve"
  },
  "include": [
    "src"
  ]
}

NOTE: I found many answers related to this error but all seems related to babel but babel is not in my package.json注意:我找到了许多与此错误相关的答案,但似乎都与babel有关,但babel不在我的 package.json 中

Your browser is trying to read a typescript file, and browsers don't read typescript.您的浏览器正在尝试读取打字稿文件,而浏览器不读取打字稿。 It needs to be transpiled to JavaScript.它需要被转换为 JavaScript。 The scripts in your package.json do this for you. package.json 中的脚本会为您执行此操作。

Without seeing what build-non-split.js does I'd say try to use the default react-scripts build:没有看到什么build-non-split.js我会说尝试使用默认的 react-scripts 构建:

node react-scripts build

Then enter the project through the resulting /dist/index.html file.然后通过生成的/dist/index.html文件进入项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReactJS 错误您可能需要适当的加载程序来处理此文件类型 - ReactJS error You may need an appropriate loader to handle this file type ReactJS,Webpack:您可能需要适当的加载器来处理此文件类型 - ReactJS ,Webpack : You may need an appropriate loader to handle this file type Materialui升级“您可能需要适当的加载程序来处理此文件类型。”问题 - Materialui upgrade “You may need an appropriate loader to handle this file type.” issue JSON 数据对 API 的跨源请求 - “您可能需要一个合适的加载器来处理这种文件类型。” - Cross-Origin Request to API for JSON data - “You may need an appropriate loader to handle this file type.” “npm run build”模块解析错误“您可能需要适当的加载程序来处理此文件类型。” - "npm run build" module parse error "You may need an appropriate loader to handle this file type." react-redux-firebase,“您可能需要适当的加载程序来处理此文件类型。” - react-redux-firebase, “You may need an appropriate loader to handle this file type.” Webpack错误:您可能需要适当的加载程序来处理此文件类型。 | @字符集“ UTF-8”; - Webpack error: You may need an appropriate loader to handle this file type. | @charset “UTF-8”; 模块解析失败:意外的令牌(7:5)您可能需要适当的加载程序来处理此文件类型。 :Webpack,Bootstrap - Module parse failed: Unexpected token (7:5) You may need an appropriate loader to handle this file type. : Webpack, Bootstrap Vue JS 2 on rails 5.1 “您可能需要一个合适的加载器来处理这种文件类型。” - Vue JS 2 on rails 5.1 'You may need an appropriate loader to handle this file type.' Webpack:&#39;你可能需要一个合适的加载器来处理这个文件类型。&#39; - 如何解决异步错误? - Webpack: 'You may need an appropriate loader to handle this file type.' - How to resolve async error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM