ember-cli-typescript icon indicating copy to clipboard operation
ember-cli-typescript copied to clipboard

Importing an ambient-type only package fails to build

Open omairvaiyani opened this issue 4 years ago • 2 comments

ember-cli: 3.16.0 node: 12.14.0 os: darwin x64

Typescript: 4.1.2

My tsconfig.json

{ "compilerOptions": { "target": "es2020", "allowJs": true, "moduleResolution": "node", "allowSyntheticDefaultImports": true, "noImplicitAny": true, "noImplicitThis": true, "alwaysStrict": true, "strictNullChecks": true, "strictPropertyInitialization": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noEmitOnError": false, "noEmit": true, "inlineSourceMap": true, "inlineSources": true, "baseUrl": ".", "module": "es2020", "experimentalDecorators": true, "paths": { "fetch": ["node_modules/ember-fetch"], "": ["types/"] } }, "include": ["app//*", "tests//", "types/**/", "mirage/**/*"] }

My tslint.json or eslint.json

{ "root": true, "parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json", "ecmaVersion": 2020, "sourceType": "module", "ecmaFeatures": { "legacyDecorators": true } },

"plugins": ["ember", "prettier", "@typescript-eslint"], "extends": [ "eslint:recommended", "plugin:ember/recommended", "plugin:qunit/recommended", "plugin:@typescript-eslint/recommended", "prettier", "prettier/@typescript-eslint" ], "env": { "browser": true }, "rules": { "prettier/prettier": ["error", { "singleQuote": true }], "ember/order-in-components": "warn", // this rule breaks on nested properties; fix is merged in master but not yet released "ember/use-brace-expansion": "off", "ember/avoid-leaking-state-in-ember-objects": "off", "no-undef": ["error"], "ember/no-observers": "off", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/no-non-null-assertion": "off" }, "overrides": [ // node files { "files": [ ".eslintrc.js", ".template-lintrc.js", "ember-cli-build.js", "testem.js", "blueprints//index.js", "config/**/.js", "lib//index.js", "server/**/.js" ], "parserOptions": { "sourceType": "script" }, "env": { "browser": false, "node": true } }, { "files": ["*.js"], "rules": { "@typescript-eslint/explicit-module-boundary-types": "off" } } ] }

My ember-cli-build.js options
{
 ...
'ember-cli-babel': {
  includePolyfill: true
},


babel: {
  plugins: [
    [require.resolve('ember-auto-import/babel-plugin'), {  exclude: ['type-fest'] }],
    [
      '@babel/plugin-transform-typescript',
      {
        allowNamespaces: true
      }
    ]
  ]
},

... }

What did you expect to see?

Importing a typescript utility library using import type {} from '..' should omit the import on build. The library we want to use is type-fest https://github.com/sindresorhus/type-fest. The package only contains ambient types, meaning there is nothing to import at runtime. My expectation with import type is that this should be completely removed during the build process.

I looked into ember-auto-import as a potential source of problem, but using their exclude: ["type-fest"] option did not help.

What happened instead?

Build fails with the following exception:

nhandledPromiseRejectionWarning: Error: Can't resolve 'type-fest' in '/Users/<me>/Documents/GitHub/<app>'
    at /Users/<me>/Documents/GitHub/<app>/node_modules/enhanced-resolve/lib/Resolver.js:180:19

omairvaiyani avatar Mar 04 '21 15:03 omairvaiyani

Thanks for the report! Hopefully one of us will be able to look into this soon!

chriskrycho avatar Mar 07 '21 00:03 chriskrycho

@omairvaiyani - are you sure you're not hitting this issue?

boris-petrov avatar Mar 15 '21 15:03 boris-petrov

I believe this is not an ember-cli-typescript specific issue, but in any case we now recommend that people switch to using ember-cli-babel for apps (as documented here) and the rollup plugin configured as part of the v2 add-on build for add-ons, in conjunction with running glint or tsc directly on their projects. Accordingly, although this should not be an issue, even if it is we will not be addressing it, as we are moving this package into maintenance mode. Thanks!

chriskrycho avatar Sep 28 '23 23:09 chriskrycho