1

I try to load this module in my typescript add. First I added the npm package and the module has been installed correctly in my node_modules folder as simpl-schema. Since there are no typings for this package I added this line:

declare var SimpleSchema: any;

I tried to import the package with import * as SimpleSchema from 'simpl-schema'; and got the message Cannot find module 'simpl-schema'. I think a got this since simpl-schema doesn't contain type information but I'm not sure.

I found tons of questions regarding this topic here, on reddit and other forums with a lot of suggestions which doesn't work for my setup. So I'm wondering whats the right way to this.

1 Answer 1

1

You are correct that you're getting Cannot find module 'simpl-schema' because types are either not available, or types are not setup properly.

Using declare var SimpleSchema: any; in your ts says that SimpleSchema is a variable (var) of type any declared outside the scope of that file. The above will not impact the result of importing simpl-schema directly. An example would be adding something like declare const window: any; to get access to the window object, if it weren't already defined for you, elsewhere.

See here for a way to leverage the any type when looking to import modules that don't have types available.

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

2 Comments

Thank you for your answer. In this case types are not available since simpl-schema doesn't contain a .d.ts. But I still don't know what I have to do to use simpl-schema in my app. If I add declare var SimpleSchema: any; the compiling process works fine but the when running in browser the SimpleSchema object couldn't be found. So I tried to add <script src="./node_modules/simpl-schema/dist/main.js"></script> to my index.html which also doesn't work.
Is SimpleSchema being made available globally from main.js (attaching SimpleSchema to window)? Typescript just trusts you when you use declare var to inform the compiler that that value will be available wherever it will run, but when the compiled output runs, SimpleSchema will need to actually be there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.