2

I have a Firebase Functions project that has "type" set to "module" in package.json so that I can use ES6 syntax. Some of the files import data from another json file with a line like:

import oAuth2Data from './client_secrets.json' assert { type: 'json' };

Recently, in my server logs, I noticed a warning from Firebase that: 'assert' is being deprecated...use 'with' instead. Unfortunately, VSCode gives me the error "'with' is not supported in strict mode" which I believe is necessary to use type:module. Is there another option that allows me to continue using strict mode?

1
  • The question should mention the exact error and that you observe it in IDE Commented Mar 2 at 0:31

2 Answers 2

2

import..with is the correct syntax, as another answer suggests, so it should be:

import oAuth2Data from './client_secrets.json' with { type: 'json' };

This is TypeScript error, that it occurs means that it's caused by TypeScript version that is too old, so it's parsed as:

import oAuth2Data from './client_secrets.json';
with { type: 'json' }

Since the question doesn't mention that the project uses TypeScript, and it happens only in IDE, the problem is specific to the latter. VS Code heavily relies on TS even in JS-only projects. This can be solved by updating VS Code and its internal TypeScript, or globally installed TypeScript, or in-project TypeScript (in case there is any). TS version that VSC uses for the project is configurable.

Sign up to request clarification or add additional context in comments.

Comments

2

The with statement is forbidden in strict mode, but the with import attribute isn't.

2 Comments

Why does VS Code give the error " 'with' statements are not allowed in strict mode." when used in the above example?
Because VS Code, apparently, is a bit dumb. Using with as import attribute works fine in strict mode, just try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.