活字体:module.exportsはしてエクスポートされたものをインポートします

Strebler:

私はいくつかの理由のためにニーズがES5に書き込まれることを、以下のテーマファイルを持っています:

module.exports.theme = {
  primaryColor: 'blue',
  borderSize: '2px',
  // ...
}

私は(作成反応するアプリ環境での)活字体ファイルでそれをインポートしたいです。だから私は、次のことをやりました。

import { theme } from "../../../../session/theme";

これは、次のエラーが発生します。

Attempted import error: 'theme' is not exported from '../../../../session/theme'.

私はまたしてエクスポートしようとしたmodule.exports.default = { ... }とデフォルトをインポートするが、それは基本的に同じこと(デフォルト値なしエクスポートを)言います。

私はこれをどのように解決する必要がありますか?

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": "react"
  },
  "include": ["src"]
}
ローマン・マクシモブ:

ES5を使用して、モジュールのコンパイルとして、あなたは使用する必要が必要とするのではなく、インポートこれを試して

const theme = require('../../../../session/theme').theme;

そうしないと、ES6でモジュールをコンパイルする必要があります

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=14520&siteId=1