dschnelldavis/angular2-json-schema-form

Identifier 'Ajv' has already been declared while migrating to Angular6

vatsalpande opened this issue · 15 comments

Issue type

I'm submitting a (check one):
[x] Bug report
[ ] Feature request
[ ] Regression (something that used to work, but stopped working in a newer version)
[ ] Support request
[ ] Documentation issue or request

Prerequisites

Before posting, make sure you do the following (check all):
[x] Confirm you are using the latest versions of all necessary packages (or if not, explain why not)
[x] Search GitHub for a similar issue or PR

Current behavior

While running ng serve below error is being thrown

ERROR in ./node_modules/angular2-json-schema-form/angular2-json-schema-form.es5.js
Module parse failed: Identifier 'Ajv' has already been declared (7:12)
You may need an appropriate loader to handle this file type.

On checking angular2-json-schema-form.es5.js - there are two entries for
import * as Ajv from 'ajv';

If one of the entry is removed manually, this error goes away

Expected behavior

No error should be thrown while building the project

IMPORTANT: How can we reproduce your problem?

Just include angular2-json-schema-form in a newly configured angular cli project and run ng serve

Environment

OS name & version: macOS Sierra
Browser name & version:
Angular version: 6
Angular JSON Schema Form version(s): ^0.7.0-alpha.1

I have the same problem. The import seems to stem from https://github.com/dschnelldavis/angular2-json-schema-form/blob/master/build.js#L129. I am not familiar with the build process but I removed it in my fork and it seems to build fine.

Any way I can update this w/o modifying the code in my node_modules folder?

3c commented

I have the same problem . because exports error component in xx.module.ts

@NgModule({
  exports: [
    CheckBoxComponent   // this is error line
    CheckboxListComponent
  ]
})

I write a component named 'CheckboxListComponent' , but spell wrong word in exports . 'CheckBoxComponent' belongs to Material

After delete the wrong line code ,it's fine

@neil-coutinho any progress on this error?

@Mathijs003 No I simply commented out the duplicate import * as Ajv from 'ajv' statement as mentioned above

I made a PR to solve this issue. I hope it will get merged soon #295

For people who can't wait for this update to get merged here's a quick fix:

$ npm install git+https://github.com/hamzahamidi/angular2-json-schema-form.git#build-angular-6 --save

You may need to install @angular/flex manually: $ npm i @angular/flex-layout
Once this branch get merged, I'll delete the branch so it will not work anymore, in respect to the repo's owner

trsh commented

With this version Im getting other problems:

core.js:1870 ERROR RangeError: Maximum call stack size exceeded at isNumber (angular2-json-schema-form.es5.js:213) at isEqual (angular2-json-schema-form.es5.js:6708) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712) at isEqual (angular2-json-schema-form.es5.js:6712)

when dealing with enums

trsh commented

It's whenever I select non-first option for enum in dropdown :/

@trsh I fixed that error in the last commit. I think I didn't update the bundles. I'll do it asap

trsh commented

From bedugger

var isEqual = function (enumValue, inputValue) {
                return enumValue === inputValue ||
                    (isNumber(enumValue) && +inputValue === +enumValue) ||
                    (isBoolean(enumValue, 'strict') &&
                        toJavaScriptType(inputValue, 'boolean') === enumValue) ||
                    (enumValue === null && !hasValue(inputValue)) ||
                    isEqual(enumValue, inputValue);
            };

The last line creates an inf recursion :(

I dont understand. It's supposed to be a lodash fn, but it's compiled like local

trsh commented

@hamzahamidi

another issue is #300, but I can't tell if its your version or old issue, because I can't install not-your-version :D

@trsh I can't seem to reproduce your issue did you try delete your package-lock.json & run:

 npm install git+https://github.com/hamzahamidi/angular2-json-schema-form.git#build-angular-6 --save
trsh commented

The first issue is fixed. Duno exactly how. I did a lot of things :). But now that isEqual appears as it should be, with WB wrapper.
The second is more an angular thing.

Tnx for your time.

Thank you for the PR @trsh! Hopefully it gets merged soon or the issues be rectified.