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

Fix support for @tsconfig/ember 3.0.0 error TS7016 #613

Closed
mayatron opened this issue Jul 17, 2023 · 6 comments
Closed

Fix support for @tsconfig/ember 3.0.0 error TS7016 #613

mayatron opened this issue Jul 17, 2023 · 6 comments

Comments

@mayatron
Copy link

Trying to use Ember CLI Page Objects 2.0.0 with TypeScript 5.1.6 throws the following error:

error TS7016: Could not find a declaration file for module 'ember-cli-page-object'.
'node_modules/ember-cli-page-object/dist/index.js' implicitly has an 'any' type.
There are types at 'node_modules/ember-cli-page-object/types.d.ts', but this result
could not be resolved when respecting package.json "exports". The 'ember-cli-page-object'
library may need to update its package.json or typings.

This seems to be related to this issue.

Updating the page objects package.json locally (as suggested in the issue above) does appear to address the issue for me, but I'm not sure about any side effects or backwards-compatibility issues the change might cause.

@bendemboski
Copy link
Contributor

Further context -- I believe this is specifically related to using "moduleResolution": 'bundler', and this patch (applied via patch-package or similar) fixes it for me:

diff --git a/node_modules/ember-cli-page-object/package.json b/node_modules/ember-cli-page-object/package.json
index cddb866..e92c917 100644
--- a/node_modules/ember-cli-page-object/package.json
+++ b/node_modules/ember-cli-page-object/package.json
@@ -25,7 +25,10 @@
   "license": "MIT",
   "author": "Santiago Ferreira",
   "exports": {
-    ".": "./dist/index.js",
+    ".": {
+      "import": "./dist/index.js",
+      "types": "./types.d.ts"
+    },
     "./*": "./dist/*",
     "./addon-main.js": "./addon-main.js"
   },

@ro0gr
Copy link
Collaborator

ro0gr commented Jul 19, 2023

Hey, thanks guys 👋

It feels reasonable for me to provide a few test scenarios to check the build against a couple of major typescript versions. Probably via ember-try scenarios...

I'll appreciate a PR! Otherwise, I'll try to take a look on a fix this weekend.

@mayatron
Copy link
Author

When I update package.json as follows:

"exports": {
  ".": {
    "import": "./dist/index.js",
    "types": "./types.d.ts"
  },
  "./*": "./dist/*",
  "./addon-main.js": "./addon-main.js"
},

... then tsc --noEmit passes, but ember build fails with the following error:

ERROR in ../../../../private/var/folders/7s/082kb7n942s1xm4t8_tpb65r0000gn/T/broccoli-20572FT45LJQ4uBmn/cache-574-webpack_bundler_ember_auto_import_webpack/tests.cjs 15:102-134
Module not found: Error: Package path . is not exported from package /private/var/folders/7s/082kb7n942s1xm4t8_tpb65r0000gn/T/broccoli-20572FT45LJQ4uBmn/cache-574-webpack_bundler_ember_auto_import_webpack/node_modules/ember-cli-page-object (see exports field in /private/var/folders/7s/082kb7n942s1xm4t8_tpb65r0000gn/T/broccoli-20572FT45LJQ4uBmn/cache-574-webpack_bundler_ember_auto_import_webpack/node_modules/ember-cli-page-object/package.json)

cleaning up...
Build Error (WebpackBundler)

webpack returned errors to ember-auto-import

However the following works for me with both tsc --noEmit and ember build.

"exports": {
  ".": {
    "import": "./dist/index.js",
    "require": "./dist/index.js",
    "types": "./types.d.ts"
  },
  "./*": {
    "import": "./dist/*",
    "require": "./dist/*",
    "types": "./types.d.ts"
  },
  "./addon-main.js": {
    "import": "./addon-main.js",
    "require": "./addon-main.js",
    "types": "./types.d.ts"
  }
},

I was able to make some progress adding a new ember-try scenario, but currently the scenario passes even without the accompanying change to package.json.

{
  name: 'ember-release-typescript-5',
  npm: {
    devDependencies: {
      '@ember/string': '^3.1.1',
      'ember-cli-typescript': '^5.2.1',
      'ember-resolver': '^10.1.1',
      'ember-source': await getChannelURL('release'),
      'typescript': '^5.1.6',
    },
  },
  env: {
    EMBER_OPTIONAL_FEATURES: JSON.stringify({
      'jquery-integration': false,
    }),
  },
}

@bendemboski
Copy link
Contributor

As I said, I'm pretty sure this has nothing to do with the typescript version, but rather using "moduleResolution": 'bundler'. I ran into this because my project uses @tsconfig/ember as the base for tsconfig.json and when I upgraded from v2 to v3 (which switches the moduleResolution) I started running into this error.

So you might be able to get a failing test by updating the test app to extend @tsconfig/ember and then have an ember-try scenario that uses v3 of @tsconfig/ember. Since this is a v2 addon, you could also just write a separate test app to test this scenario 🤷

@mayatron mayatron changed the title Fix support for TypeScript 5.x which throws error TS7016 Fix support for @tsconfig/ember 3.0.0 error TS7016 Jul 26, 2023
@mayatron
Copy link
Author

I've opened #614 to address this. Please let me know if you have any feedback, happy to iterate on this.

Thanks @bendemboski for the tips!

@ro0gr
Copy link
Collaborator

ro0gr commented Aug 2, 2023

Just published the fix https://github.com/san650/ember-cli-page-object/releases/tag/v2.1.0. Thanks everyone!

@ro0gr ro0gr closed this as completed Aug 2, 2023
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