Skip to content

Etebase library does not compile with "tsconfig.json:compilerOptions.strict: true" #15

@hlovdal

Description

@hlovdal

Trying to use the etebase library in an Angular project initialized with strict option fails. Steps to reproduce:

  1. Create minimal project:
$ cd /tmp
$ ng new --defaults --strict test
CREATE test/README.md (1013 bytes)
...
CREATE test/e2e/src/app.po.ts (274 bytes)
✔ Packages installed successfully.
    Successfully initialized git.
$ cd test
$
  1. Install and use etebase.
$ npm install --save etebase
...
+ etebase@0.42.0
added 11 packages from 13 contributors and audited 1626 packages in 14.594s
...
$ $EDITOR src/app/app.component.ts
...
$ git diff src/app/app.component.ts
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 29d65ec..bdd1e6a 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -1,4 +1,5 @@
 import { Component } from '@angular/core';
+import { Account } from 'etebase';

 @Component({
   selector: 'app-root',
@@ -7,4 +8,7 @@ import { Component } from '@angular/core';
 })
 export class AppComponent {
   title = 'test';
+  public test(): void {
+    Account.login("username", "password", "url");
+  }
 }
$
  1. Running test now fails:
$ npm run test -- --watch=false

> test@0.0.0 test /tmp/test
> ng test "--watch=false"
...
✔ Browser application bundle generation complete.

Error: node_modules/etebase/dist/lib/Crypto.d.ts:1:21 - error TS7016: Could not find a declaration file for module 'libsodium-wrappers'. '/tmp/test/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/libsodium-wrappers` if it exists or add a new declaration (.d.ts) file containing `declare module 'libsodium-wrappers';`

1 import _sodium from "libsodium-wrappers";
                      ~~~~~~~~~~~~~~~~~~~~


Error: node_modules/etebase/dist/lib/Helpers.d.ts:1:21 - error TS7016: Could not find a declaration file for module 'libsodium-wrappers'. '/tmp/test/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/libsodium-wrappers` if it exists or add a new declaration (.d.ts) file containing `declare module 'libsodium-wrappers';`

1 import _sodium from "libsodium-wrappers";
                      ~~~~~~~~~~~~~~~~~~~~


Error: node_modules/etebase/dist/lib/OnlineManagers.d.ts:1:17 - error TS7016: Could not find a declaration file for module 'urijs'. '/tmp/test/node_modules/urijs/src/URI.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/urijs` if it exists or add a new declaration (.d.ts) file containing `declare module 'urijs';`

1 import URI from "urijs";
                  ~~~~~~~



npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.0.0 test: `ng test "--watch=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     $HOME/.npm/_logs/2021-03-03T20_38_58_942Z-debug.log
$
  1. Installing the missing type packages makes the errors a bit less obscure, but does not fix the underlying problem:
$ npm i --save-dev @types/libsodium-wrappers
...
+ @types/libsodium-wrappers@0.7.9
added 1 package from 1 contributor, removed 1 package and audited 1627 packages in 15.381s
...
$ npm i --save-dev @types/urijs
...
+ @types/urijs@1.19.14
added 1 package from 10 contributors and audited 1628 packages in 14.163s
...
$ npm run test -- --watch=false
...
✔ Browser application bundle generation complete.

Error: node_modules/etebase/dist/lib/Crypto.d.ts:1:8 - error TS1192: Module '"/tmp/test/node_modules/@types/libsodium-wrappers/index"' has no default export.

1 import _sodium from "libsodium-wrappers";
         ~~~~~~~


Error: node_modules/etebase/dist/lib/Helpers.d.ts:1:8 - error TS1192: Module '"/tmp/test/node_modules/@types/libsodium-wrappers/index"' has no default export.

1 import _sodium from "libsodium-wrappers";
         ~~~~~~~


Error: node_modules/etebase/dist/lib/OnlineManagers.d.ts:1:8 - error TS1259: Module '"/tmp/test/node_modules/@types/urijs/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

1 import URI from "urijs";
         ~~~

  node_modules/@types/urijs/index.d.ts:26:1
    26 export = URI;
       ~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.



npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.0.0 test: `ng test "--watch=false"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     $HOME/.npm/_logs/2021-03-03T20_40_06_933Z-debug.log
$

If the project is created with just ng new --defaults test then no errors are generated. The main difference between strict and unstrict is the following difference in tsconfig.json:

--- test/tsconfig.json  2021-03-03 21:57:54.304950915 +0100
+++ test.strict/tsconfig.json   2021-03-03 21:59:09.016755082 +0100
@@ -4,6 +4,10 @@
   "compilerOptions": {
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",
+    "forceConsistentCasingInFileNames": true,
+    "strict": true,
+    "noImplicitReturns": true,
+    "noFallthroughCasesInSwitch": true,
     "sourceMap": true,
     "declaration": false,
     "downlevelIteration": true,
@@ -18,6 +22,9 @@
     ]
   },
   "angularCompilerOptions": {
-    "enableI18nLegacyMessageIdFormat": false
+    "enableI18nLegacyMessageIdFormat": false,
+    "strictInjectionParameters": true,
+    "strictInputAccessModifiers": true,
+    "strictTemplates": true
   }
 }

Testing with a project created with without --strict but just adding "strict": true, to compilerOptions in tsconfig.json also produces the errors, thus compilerOptions.strict: true is the triggering factor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions