Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when using this in angular/webpack/browserify #47

Open
Masterxilo opened this issue Mar 25, 2019 · 8 comments
Open

Problem when using this in angular/webpack/browserify #47

Masterxilo opened this issue Mar 25, 2019 · 8 comments
Assignees

Comments

@Masterxilo
Copy link

I recently wanted to use this in an angular 7 project and I got

ERROR in ./node_modules/text-to-svg/build/src/index.js
Module not found: Error: Can't resolve 'path' in '/mnt/d/Users/E513185/OneDrive/signaletikeditor/signaletikeditor-frontend/node_modules/text-to-svg/build/src'
@Masterxilo
Copy link
Author

The solution is to use npm install path to install the 'path' module which native nodejs provides by itself but must be manually installed for webpack to understand it.

@Masterxilo
Copy link
Author

'npm install process' is also necessary to avoid the subsequent error message in the browser

path.js:25 Uncaught ReferenceError: process is not defined
    at Object../node_modules/path/path.js (path.js:25)

@Masterxilo
Copy link
Author

That actually does not fix the problem.

It is well known that angular has a problem with these libraries... see for example https://blog.lysender.com/2018/07/angular-6-cannot-resolve-crypto-fs-net-path-stream-when-building-angular/

Now how can I use this in an Angular client application successfully?

@Masterxilo Masterxilo reopened this Mar 25, 2019
@Masterxilo
Copy link
Author

I had other problems like

ERROR in src/app/_signaletic/plate/plate/plate.component.ts(50,12): error TS2339: Property 'process' does not exist on type 'Window'.
Uncaught ReferenceError: __dirname is not defined
Uncaught TypeError: Arguments to path.join must be strings

I could finally solve the problem using the following HACKFIX (after npm install'ing process and path):

//import TextToSVG from "text-to-svg"; // does not work
// HACKFIX for
// Uncaught ReferenceError: process is not defined and other problems
//at Object../node_modules/path/path.js
window["process"] = {}; window["__dirname"] = ''; const TextToSVG = require("text-to-svg");

@Masterxilo Masterxilo changed the title Problem when using this in angular Problem when using this in angular/webpack/browserify Mar 25, 2019
@Masterxilo
Copy link
Author

Which browserification library was used in this project?

@shrhdk shrhdk self-assigned this Mar 26, 2019
@Masterxilo
Copy link
Author

I would consider this issue resolved when it is possible to use this library in angular using

import TextToSVG from "text-to-svg";

I am not quite sure of all the steps required for you guys to enable this.

For now, I can work with my hackfix mentioned above:

//import TextToSVG from "text-to-svg"; // does not work
window["process"] = {}; window["__dirname"] = ''; const TextToSVG = require("text-to-svg");

@antoine382
Copy link

Did you fix your problem ? I have exactly the same !

@Masterxilo
Copy link
Author

@antoine382 look at the end of my post above. You can define the missing variables as dummy globals on the window object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants