0

I am working on a Cloud Functions project initialized with Firebase SDK. I chose typescript as a language. I would like to import a non js, non ts file as a string, using import syntax. For example:

import * as content from './templates/text.md'

But obviously, I get an error:

error TS2307: Cannot find module './templates/text.md'.

How should I configure my project (.d.ts files? tsconfig.json? something else), so that it compiles correctly.

For reference of how the project is initialized with Firebase SDK: https://firebase.google.com/docs/functions/get-started

1 Answer 1

1

You can't import something that doesn't parse as JavaScript. Instead, if you want to get the contents of some other file, you should read it with something like readFile().

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

2 Comments

It is possible, when typescript is compiled with webpack (see: webpack.js.org/guides/typescript/#importing-other-assets). Is this not possible with tsc compiler?
Cloud Functions for Firebase doesn't use webpack or any other bundling system. All the files are simply uploaded as they sit in the functions folder, except node_modules, which is reconstituted by npm on the server.

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.