このコードは正常に動作していました。
Node 17にアップグレードしたからなのか何なのか分かりませんが、今は
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]:
Module "file:///Users/xxxxx/code/projects/xxxxx/dist/server/data/countries.json"
needs an import assertion of type "json"
私の中にapi.ts
は:
import countryTable from './data/countries.json';
以下は私が開始する方法です。api.ts
これは以下で使用されますserver.ts
:
NODE_ENV=production node --optimize_for_size --trace-warnings --experimental-json-modules --no-warnings server/server.js
ベストアンサー1
更新: 提案によると、新しいキーワードはwith
の代わりに ですassert
が、assert
互換性の理由からそのまま残される予定です。新しいコードは次のようになります。
import countryTable from "./data/countries.json" with { type: "json" };
以下を使用する必要があります:
import countryTable from "./data/countries.json" assert { type: "json" };