formio.js: [BUG] FormBuilder error: Uncaught (in promise) Missing projectId

Environment

Please provide as many details as you can:

  • Hosting type
    • [] Form.io
    • [x ] Local deployment
      • Version: N/A, custom backend
  • Formio.js version: 4.13
  • Frontend framework: React or vanilla JavaScript
  • Browser: Google Chrome
  • Browser version: Version 90.0.4430.93 (Official Build) (64-bit)

Steps to Reproduce

  1. Go to https://formio.github.io/formio.js/app/builder
  2. Open Google Chrome console

Expected behavior

No error in the console

Observed behavior

Error in the console:

builder:1 Uncaught (in promise) Missing projectId
Promise.then (async)
WebformBuilder @ WebformBuilder.js:382
create @ FormBuilder.js:82
setForm @ Form.js:253
Form @ Form.js:122
_createSuperInternal @ FormBuilder.js:50
FormBuilder @ FormBuilder.js:72
(anonymous) @ builder:137

We are getting the same error when rendering FormBuilder from FormIO 4.13 in our app. Before 4.13 version it was ok.

Example

Example is already present in the official FormBuilder demo page: https://formio.github.io/formio.js/app/builder

Is there any workaround for this error to not appear? Maybe some option to set, so the projectId is not missing anymore?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 22 (6 by maintainers)

Most upvoted comments

Functionality is fine, but the error logging is annoying, particularly if you have browser logs getting shipped to a logging service.

@simonv3, let us know if you see the issue moving forward. Glad to hear that it is no longer occurring.

We are working on making a stable release of 4.14.0.

Change from the Branches section to the tags and you will see the latest version of 4.14.0 is rc.31.

formio js_Changelog md at master · formio_formio j

It’s because formio’s default constructor function doesn’t pass the [options] argument, and the code that looks for it finds no 2nd argument, and thus options is empty, and thus options.base is empty, and thus projectUrl cannot be determined, so it is a blank string, and thus this error gets shoved in the console because the evaluation of empty-string returns false (!“” == true).

So yea even if you specify base, it has this logical flaw. (with proposed change below, specifying options.base would fix) var formio = new _Formio.default(_Formio.default.projectUrl); should be var formio = new _Formio.default(_Formio.default.projectUrl, _this.options);

It looks benign though, the system still works fine for me. It’s just hard red in the console, and totally pointless (in terms of being so easily fixable). Are you guys experiencing an actual problem with this? Or just seeing it in console like I am. I thought i was having an issue, but was something else, but ended up deep diving this anyway.

Have the same error and it seems blocker for me considering upgrade to 4.13.x version Screenshot 2021-10-21 at 10 28 19

Any updates about the issue? @travist

In React this will actually pop up the error message pop-up that blocks the entire screen while editing, making working on a page with formio on it a bit a of a pain.

So the issue comes from the WebformBuilder class:

https://github.com/formio/formio.js/blob/0f3672cc2a94d89ae6b47b5f53dc12ecb10f74e9/src/WebformBuilder.js#L231-L243

So the builder calls loadProject using the current Formio instance to retrieve the project settings in search for form global settings. This function fails if projectId is empty. There are 3 ways to determine the projectId:

  1. Checking that the api url has the format .../project/:projectId/... (explicit project id)
  2. Checking if the url hostname matches the base url and getting the first path portion of the url (subdirectories)
  3. Checking if hostname has a subdomain (subdomain)

https://github.com/formio/formio.js/blob/0f3672cc2a94d89ae6b47b5f53dc12ecb10f74e9/src/Formio.js#L175-L200

There is also a preliminary check to determine this as well:

https://github.com/formio/formio.js/blob/0f3672cc2a94d89ae6b47b5f53dc12ecb10f74e9/src/Formio.js#L106-L111

Of course this approach is very untrustworthy as it is made to work with the commercial setup of form.io, and unless you manually pass on the correct formio options before creating the Formio instance, it most probably fail (as an example, you may pass an IP address as path and baseURL and it will treat it as a subdomain type of project).

In fact, the official documentation states what are the requirements of any local deployment (of the commercial build)

https://help.form.io/developer/onpremise/#dns-setup

Here are some results for different paths (without setting options):

import { Formio } from 'formiojs';

const formio = new Formio(path);
path projectId projectUrl formId formUrl
http://localhost localhost http://localhost
http://localhost/project/:projectId :projectId http://localhost/project/:projectId
http://localhost/form/:formId localhost http://localhost :formId http://localhost/form/:formId
http://localhost/alias localhost http://localhost alias http://localhost/alias
http://example.com http://example.com
http://example.com/project/:projectId :projectId http://example.com/project/:projectId
http://example.com/form/:formId http://example.com :formId http://example.com/form/:formId
http://example.com/alias http://example.com alias http://example.com/alias
http://subdomain.example.com subdomain http://subdomain.example.com
http://subdomain.example.com/project/:projectId :projectId http://subdomain.example.com/project/:projectId
http://subdomain.example.com/form/:formId subdomain http://subdomain.example.com :formId http://subdomain.example.com/form/:formId
http://subdomain.example.com/alias subdomain http://subdomain.example.com alias http://subdomain.example.com/alias
http://127.0.0.1 127 http://127.0.0.1
http://127.0.0.1/project/:projectId :projectId http://127.0.0.1/project/:projectId
http://127.0.0.1/form/:formId 127 http://127.0.0.1 :formId http://127.0.0.1/form/:formId
http://127.0.0.1/alias 127 http://127.0.0.1 alias http://127.0.0.1/alias

Any updates regarding this bug? It is blocker issue

I am facing similar issue with angular.

“angular-formio”: “^4.4.5”, “formiojs”: “^4.13.2”,

zone.js:690 Unhandled Promise rejection: Missing projectId ; Zone: <root> ; Task: Promise.then ; Value: Missing projectId undefined

can anyone help please?

Hi guys, any info here? @travist , @wag110894 ?