3

我在带有 CRA 的 React 项目中使用 lingui 包,在使用 lingui/macro modules t 方法时出现错误。

当我构建项目时收到 webpack 警告消息。

像这样。

关键依赖:依赖的请求是一个表达式

这似乎是由于 bable-plugin-macro,但我不知道确切的原因。帮我!!

这是我的错误和代码

import { t } from '@lingui/macro';

render() {
return (
  <ListItemText primary={i18n._(t`Apps`)} />
)
}

错误:

ERROR in ./node_modules/import-fresh/node_modules/resolve-from/index.js
Module not found: Error: Can't resolve 'module' in 'D:\myProject\node_modules\import-fresh\node_modules\resolve-from'
 @ ./node_modules/import-fresh/node_modules/resolve-from/index.js 3:15-32
 @ ./node_modules/import-fresh/index.js
 @ ./node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/loaders.js
 @ ./node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/index.js

包.json:

"dependencies": {
    "@babel/core": "^7.10.2",
    "@condenast/xml-to-react": "^1.0.0",
    "@date-io/moment": "1.3.13",
    "@lingui/core": "^2.9.1",
    "@lingui/react": "^2.9.1",
    "@loadable/component": "^5.12.0",
    "@material-ui/core": "^4.2.1",
    "@material-ui/icons": "^4.2.1",
    "@material-ui/lab": "^4.0.0-alpha.21",
    "@material-ui/pickers": "^3.2.10",
    "@svgr/webpack": "4.1.0",
    "@types/crypto-js": "^3.1.43",
    "@types/jxon": "^2.0.0",
    "@types/lingui__macro": "^2.7.3",
    "@types/lingui__react": "^2.8.2",
    "@types/loadable__component": "^5.10.0",
    "@types/lodash": "^4.14.149",
    "@types/material-ui": "^0.21.7",
    "@types/node": "^12.12.21",
    "@types/react-beautiful-dnd": "^12.1.2",
    "@types/react-loadable": "^5.5.3",
    "@types/react-router-dom": "^5.1.3",
    "@types/recharts": "^1.8.10",
    "@typescript-eslint/eslint-plugin": "1.6.0",
    "@typescript-eslint/parser": "1.6.0",
    "axios": "^0.19.0",
    "babel-eslint": "10.0.1",
    "babel-jest": "^24.8.0",
    "babel-loader": "^8.1.0",
    "babel-plugin-named-asset-import": "^0.3.2",
    "babel-preset-react-app": "^9.0.0",
    "camelcase": "^5.2.0",
    "case-sensitive-paths-webpack-plugin": "2.2.0",
    "crypto-js": "^4.0.0",
    "css-loader": "2.1.1",
    "dotenv": "6.2.0",
    "dotenv-expand": "4.2.0",
    "eslint": "^5.16.0",
    "eslint-config-react-app": "^4.0.1",
    "eslint-loader": "2.1.2",
    "eslint-plugin-flowtype": "2.50.1",
    "eslint-plugin-import": "2.16.0",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-react": "7.12.4",
    "eslint-plugin-react-hooks": "^1.5.0",
    "file-loader": "3.0.1",
    "fs-extra": "7.0.1",
    "html-webpack-plugin": "4.0.0-beta.5",
    "identity-obj-proxy": "3.0.0",
    "is-wsl": "^1.1.0",
    "jest": "24.7.1",
    "jest-environment-jsdom-fourteen": "0.1.0",
    "jest-resolve": "24.7.1",
    "jest-watch-typeahead": "0.3.0",
    "jxon": "^2.0.0-beta.5",
    "lodash": "^4.17.15",
    "material-table": "^1.54.2",
    "md5": "^2.2.1",
    "mini-css-extract-plugin": "0.5.0",
    "mobx": "4.3.1",
    "mobx-react": "^6.1.1",
    "moment": "^2.24.0",
    "optimize-css-assets-webpack-plugin": "5.0.1",
    "pnp-webpack-plugin": "1.2.1",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "postcss-normalize": "7.0.1",
    "postcss-preset-env": "6.6.0",
    "postcss-safe-parser": "4.0.1",
    "react": "^16.8.6",
    "react-app-polyfill": "^1.0.1",
    "react-beautiful-dnd": "^13.0.0",
    "react-contenteditable": "^3.3.2",
    "react-dev-utils": "^9.0.1",
    "react-dom": "^16.8.6",
    "react-json-editor-ajrm": "^2.5.9",
    "react-loadable": "^5.5.0",
    "react-perf-devtool": "^3.1.8",
    "react-router-dom": "^5.0.1",
    "recharts": "^1.8.5",
    "resolve": "1.10.0",
    "semver": "6.0.0",
    "style-loader": "0.23.1",
    "terser-webpack-plugin": "1.2.3",
    "ts-pnp": "1.1.2",
    "tslint": "^5.20.1",
    "url-loader": "1.1.2",
    "uuid": "^7.0.2",
    "validator": "^11.1.0",
    "webpack": "4.29.6",
    "webpack-dev-server": "3.2.1",
    "webpack-manifest-plugin": "2.0.4",
    "workbox-webpack-plugin": "4.2.0"
  },
"babel": {
    "presets": [
      "react-app",
      "babel-preset-env",
      "babel-preset-react",
      "@lingui/babel-preset-react"
    ],
    "plugins": [
      "macros",
      "babel-plugin-macros",
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ]
    ],
    "ignore": [
      "node_modules",
      "public/dist"
    ]
  },
"devDependencies": {
    "@babel/plugin-proposal-decorators": "^7.7.4",
    "@babel/preset-env": "^7.10.2",
    "@lingui/cli": "^2.9.1",
    "@lingui/macro": "^2.9.1",
    "autoprefixer": "^9.6.1",
    "awesome-typescript-loader": "^5.2.1",
    "babel-core": "^7.0.0-bridge.0",
    "babel-plugin-macros": "^2.8.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "cross-env": "^5.2.0",
    "cssnano": "^4.1.10",
    "eslint-config-prettier": "^6.0.0",
    "eslint-plugin-prettier": "^3.1.0",
    "fork-ts-checker-webpack-plugin": "^3.1.1",
    "hard-source-webpack-plugin": "^0.13.1",
    "node-cmd": "^3.0.0",
    "node-sass": "^4.9.3",
    "prettier": "^1.18.2",
    "prettier-eslint": "^9.0.0",
    "sass-loader": "^7.1.0",
    "source-map-loader": "^0.2.4",
    "ts-loader": "^6.2.1",
    "typescript": "^3.7.3",
    "typescript-eslint-parser": "^18.0.0",
    "webpack-cli": "^3.3.6"
  },
4

0 回答 0