Skip to content

module-interop/prefer-json-modules

enforce json imports to have the {type: "json"} attribute.

  • ⚙️ This rule is included in plugin.configs.recommended.
  • 💡 Some problems reported by this rule are manually fixable by editor suggestions.

📖 Rule Details

This rule reports JSON imports that do not have the {type: "json"} attribute.

Although the bundler and some runtimes (or loaders) allow you to import JSON without the {type: "json"} import attribute for interoperability, but this is not safe.
When importing JSON, it is best to use the {type: "json"} import attribute.

js
/* eslint module-interop/prefer-json-modules: 'error' */

/* ✓ GOOD */
import x from './data.json' with {type: "json"};

/* ✗ BAD */
import y from 
'./data.json'
;

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-module-interop v0.3.0

🔍 Implementation