Importing tex2max.js into an angular project via npm / index.html - javascript

When I try to import tex2max using declare var tex2max: any; I get a ReferenceError: tex2max is not defined. But this doesn't occur with other npm packages. I have tried binding the scripts by installing the npm package and through the script tag in index.html to no avail.
Here is a CDN file of the source code:
https://unpkg.com/tex2max#1.3.0/lib/tex2max.js

If the project author corrected their bundle a little you could do:
import TeX2Max from 'tex2max';
But that ends in error [EDIT: on stackblitz]
Error in /turbo_modules/tex2max#1.3.0/lib/tex2max.js (13:28806)
Cannot assign to read only property 'exports' of object '[object Object]'
The best option is to file an issue with the author.
Stackblitz example

Related

Errors when try to use pdf2json with typescript

when i try to import pdf2json (3.0.1) in my node project (typescript) iam getting this error
Could not find a declaration file for module 'pdf2json'
Also i try to install #types/pdf2json for typescript and there is not available.
How i can solve this
install #types/pdf2json for typescript and there is not available.
Looks like you're right that there are currently no types available, but that's a work in progress and they may exist soon: https://github.com/modesty/pdf2json/pull/278

"Provided module can't be loaded" error when trying to load GoogleCloud Datastore module with Nodejs 8

As part of the implementation of a Cloud Function under Google Cloud Platform, executed with Nodejs 8, I have to store information in GCP Datastore.
I use TypeScript which is compiled in Javascript.
I have the following error when I try to import the "#google-cloud/datastore" module:
Provided module can't be loaded. Is there a syntax error in your
code? Detailed stack trace: TypeError: extend must be a string
I tried 2 ways to import the module and each time I get the same error:
import {Datastore} from '#google-cloud/datastore';
const datastore = new Datastore();
or
const datastore = require('#google-cloud/datastore');
I also tried to install different versions of the module, nothing helps.
Finally, I realized that even when the module is not installed (I executed the command npm uninstall #google-cloud/datastore), I get the exact same error when logically, when we try to import a module which is not installed, we should have the following error:
Provided module can't be loaded. Did you list all required modules
in the package.json dependencies? Detailed stack trace: Error:
Cannot find module 'test'
Has anyone ever encountered this problem or would have a clue why I get this error?
I faced the same issue while deploying the functions, later I realized that I installed the packages in wrong location.
My folder structure was this:
/
functions
node_modules
index.js
...
By mistake I installed all the packages at / level:
/
functions
node_modules
index.js
...
node_modules
So all my packages were in the outer node_modules.

Can't use lib after import via npm

I'm trying to use flexibility lib inside my Laravel projet. So I ran npm i flexibility --save and require it inside my app.js file:
require('flexibility/flexibility.js');
...
flexibility(document.documentElement);
But I receive an alert:
Uncaught ReferenceError: flexibility is not defined
Require the name of the package, and set it in the window object
In bootstrap.js
window.flexibility = require('flexibility');
And in app.js or from the console
flexibility(document.documentElement);
Hope this helps

Could not find a declaration file for module while importing a node module using ES6

I have setup loopback 4 and trying to write a new controller for my Braintree API payments. I have installed the Braintree npm module and using
import {braintree} from 'braintree';
to import into a controller and use in an endpoint. But it is throwing me following error:
*src/controllers/braintree.controller.ts:23:25 - error TS7016: Could not find a declaration file for module 'braintree'. '/home/oem/Learning/learn-loopback/my-todo-app/node_modules/braintree/index.js' implicitly has an 'any' type.
Try `npm install #types/braintree` if it exists or add a new declaration (.d.ts) file containing `declare module 'braintree';*`
When I try the es5 way of importing it is working fine.
Not sure how to fix this.
The braintree type does not seem to exist yet. So here you have 2 possibilities:
You create a type file as suggested in the error, but you need to have a good knowledge of the braintree library.
Replace import {braintree} from 'braintree'; with const braintree = require('braintree'); but you won't have access to all the typescript magic, so be careful when manipulating this library.

Could not find a declaration file for module 'react-native-foo-package'

while I added any component to my pure react-native project, the application screen turns to the white empty page.
The import 'react-native-foo-package' line has '...' near the package name, and it has this message:
[ts]
not find a declaration file for module 'react-native-foo-package'. '/project/node_modules/'react-native-foo-package'/index.js' implicitly has an 'any' type.
Try npm install #types/'react-native-foo-package' if it exists or add a new declaration (.d.ts) file containing declare module 'react-native-foo-package';
npm install #types/'react-native-foo-package' couldn't help, because this package doesn't exist in npm.
I don't use any typescript file or related code to typescript.
react: "16.6.0-alpha.8af6728"
react-native: "0.57.4"
This question Could not find a declaration file for module 'module-name'. '/path/to/module-name.js' implicitly has an 'any' type doesn't answer my question, because, in my package.json file, there is no "main" exists.
Well #Samane Yaghoobi is right! it has nothing to do with "main":"index.js".
Here's what you should do. After successfully setting up the library in your project on whatever platform (VsCode or Atom). Re run the project from the command line => react-native run-android. After that, navigate to your project in Android Studio. Then open up build.gradle and sync your gradle again. Then just to make sure, checkout the MainApplication in Android Studio to see if the file(e.g. import com.whatever.foo) imported properly, if everything looks good, you are good to go. If you need further instructions in setting up the library in VsCode/Atom let me know, I will create visual presentation to make things much more clear.

Categories