typescript-memoize icon indicating copy to clipboard operation
typescript-memoize copied to clipboard

Not webpack friendly

Open theogravity opened this issue 8 years ago • 3 comments

I'm using https://github.com/storybooks/storybook along with Typescript 2.4.2 - storybook uses webpack to generate its output. When using typescript-memoize, I get the following:

WARNING in ./node_modules/typescript-memoize/dist/memoize-decorator.js
3:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

I think this is due to how the export is defined within a function.

theogravity avatar Aug 12 '17 07:08 theogravity

Indeed. The export cannot be statically resolved with the current UMD build.

@darrylhodgins it would be cool to also provide a build with ES 2015 import/exports. The path can then be specified in the module key of package.json (like here). That way, tools like Webpack and Rollup will choose the ESM version, while you still support older setups with main.

Workaround 1 - import the file directly:

import { Memoize } from 'typescript-memoize/src/memoize-decorator';

Workaround 2 - set up a Webpack alias:

resolve: {
    alias: {
        // The UMD build of typescript-memoize can't be statically resolved by Webpack.
        // See https://github.com/darrylhodgins/typescript-memoize/issues/7
        'typescript-memoize$': modulesRoot('typescript-memoize/src/memoize-decorator.ts')
    }
}

toverux avatar Sep 04 '17 13:09 toverux

Workaround 1 gives me an error:

Module build failed: Error: node_modules/typescript-memoize/src/memoize-decorator.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).

MickL avatar Mar 23 '18 17:03 MickL

Check your tsconfig configuration so that this file can be included in the compilation.

toverux avatar Mar 24 '18 12:03 toverux