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でモジュールをコンパイルする必要があります