I want to use javascript-stringify in my angular project (or an equivalent library), but nothing I've tried thus far seems to work. I have read through a number of similar questions like mine and yet the solution evades me.
When I do:
import * as javascriptStringify from 'javascript-stringify';
I see the following error:
ERROR in src/app/prospecting/prospect-engagement/prospect-engagement.component.ts(27,13): error TS6133: 'javascriptStringify' is declared but never used.
src/app/prospecting/prospect-engagement/prospect-engagement.component.ts(27,38): error TS2497: Module '"node_modules/javascript-stringify/javascript-stringify"' resolves to a non-module entity and cannot be imported using this construct.
When I do:
import stringify from 'javascript-stringify';
I see the following error:
ERROR in src/app/prospecting/prospect-engagement/prospect-engagement.component.ts(27,8): error TS1192: Module '"node_modules/javascript-stringify/javascript-stringify"' has no default export.
src/app/prospecting/prospect-engagement/prospect-engagement.component.ts(27,8): error TS6133: 'stringify' is declared but never used.
Here's the output of ng --version:
$ ng --version
Your global Angular CLI version (1.5.4) is greater than your local
version (1.5.0). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 1.5.0
Node: 8.9.1
OS: darwin x64
Angular: 5.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.34
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.38
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.8
typescript: 2.5.3
webpack: 3.8.1
Can someone show me a way to use this library...or point me to another library that offers the same functionality?
Update:
I found that if I change the file node_modules/javascript-stringify/javascript-stringify.d.ts
from export = stringify;
to export default stringify;
, then import stringify from 'javascript-stringify';
works as expected.
However, the code under node_modules is subject to change and will definitely lose my changes when built inside Docker when npm install
is run. Is this the best way forward? If so, what is the best way to make my changes permanent?
I never got the npm module javascript-stringify to work, but I was able to port it to be an Angular 5 / Typescript service, where it works fine. The original module is MIT license and so is my ported code below: