Import a JSON file content from a Node.JS module
Emmanuel Gautier / May 22, 2023
1 min read
With the new Node.JS modules, it is possible to read JSON file content with the import function which is quite simple but you have to do it the right way.
If you just make as follow you will have the needs an import assertion of type "json"
error:
import packageJSON from './package.json';
The reason is that you have to assert the type even if Node.js understand it is a JSON. According to tc39/proposal-import-attributes, you should write the import with an assertion like this:
import packageJSON from './package.json' assert { type: 'json' };
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Related Posts
Read Package.json file from Node.JS module
When you write a program you may want to read the content of the package.json file like what is the current package version. Here is one very simple way to read the content of this file.
Read Package.json file from Node.JS module
When you write a program you may want to read the content of the package.json file like what is the current package version. Here is one very simple way to read the content of this file.
Configure yarn version for Cloudflare page build
With the new Cloudflare page build system, yarn package manager version can be more than version 1. But we can keep yarn version 1 configuring the build system with a package.json property.
Featured Posts
Introducing new blog about OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.