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

Webpack 2.0 - Cannot read property 'unsafeCache' of undefined #283

Closed
donaldpipowitch opened this issue Sep 20, 2016 · 16 comments
Closed

Webpack 2.0 - Cannot read property 'unsafeCache' of undefined #283

donaldpipowitch opened this issue Sep 20, 2016 · 16 comments

Comments

@donaldpipowitch
Copy link
Contributor

donaldpipowitch commented Sep 20, 2016

Please read right to the bottom of this thread for an approach that seems to work.

Using webpack@2.1.0-beta.23:

ERROR in ./src/index.tsx
Module build failed: TypeError: Cannot read property 'unsafeCache' of undefined
    at makeResolver (/Users/foo/node_modules/ts-loader/resolver.js:35:57)
    at ensureTypeScriptInstance (/Users/foo/node_modules/ts-loader/index.js:207:20)
    at Object.loader (/Users/foo/node_modules/ts-loader/index.js:387:14)

Used as:

export const tsLoader = {
  test: /\.ts(x?)$/,
  loader: `ts-loader?silent=true`
};

@josiah1888
Copy link

+1 heeeelp

@donaldpipowitch
Copy link
Contributor Author

I switched to https://github.com/s-panferov/awesome-typescript-loader. Works fine.

@johnnyreilly
Copy link
Member

I'm afraid ts-loader is untested with WebPack 2 to my knowledge. awesome-typescript-loader is probably the best choice if you're after WebPack 2.0 support now. Myself I haven't used 2.0 as it's still in beta (and 1 handles my use cases)

@r-park
Copy link

r-park commented Sep 21, 2016

For me, this only happens when I use the LoaderOptionsPlugin with an options key:

new LoaderOptionsPlugin({
  debug: false,
  options: { ... }
})

Remove options and it works fine. Fails even if options is an empty object literal:

new LoaderOptionsPlugin({
  debug: false,
  options: {}
})

@jeffijoe
Copy link

I tried awesome-typescript-loader and couldn't get it working so I decided to take a stab at figuring out how to fix this.

@r-park @johnnyreilly @donaldpipowitch @josiah1888 by console.loging in the place the error occured, I found that the options is actually the options from the LoaderOptionsPlugin. By doing this:

new LoaderOptionsPlugin({
  debug: false,
  options: {
    resolve: {}
  }
})

Everything runs again.

@johnnyreilly
Copy link
Member

Thanks @jeffijoe - we should probably include this in the docs somewhere to improve discovery. Well done for finding out!

@johnnyreilly johnnyreilly changed the title Cannot read property 'unsafeCache' of undefined Webpack 2.0 - Cannot read property 'unsafeCache' of undefined Oct 22, 2016
@nitimmerman
Copy link

@jeffijoe: Thanks! That did the trick for me also!

@schickling
Copy link

schickling commented Nov 15, 2016

Also switched to awesome-typescript-loader. Any update when this will work again out-of-the-box without the workaround (which broke SASS for me)?

@clydin
Copy link

clydin commented Nov 15, 2016

The workaround isn't really a workaround as the resolver is not properly configured if you pass in an empty resolve object.

The issue is that when LoaderOptionsPlugin is used, the loader doesn't get the full webpack config but instead only what is contained within the object provided to LoaderOptionsPlugin.

@donaldpipowitch
Copy link
Contributor Author

@jeffijoe Your workaround seems to work for me now without visible problems. But it would be great if the workaround wouldn't be needed.

@jeffijoe
Copy link

jeffijoe commented Dec 9, 2016

@donaldpipowitch Me too, this is how I feel about it:

In the ghettoooo

@johnnyreilly
Copy link
Member

Would someone like to submit a PR to resolve this?

@johnnyreilly
Copy link
Member

@johnnyreilly
Copy link
Member

I've documented the workaround in the readme here: https://github.com/TypeStrong/ts-loader#webpack

@johnnyreilly
Copy link
Member

We now have an example in our examples section which demonstrates using ts-loader with webpack 2. I'm still not sure if the unsafe cache thing is actually a ts-loader issue; it feels like required configuration. FWIW in our example we supply all the webpack config options to the loader options plugin.

@johnnyreilly
Copy link
Member

The workaround is now documented on the readme and since this is for the Loader Options Plugin which is due to be short-lived I'm going to close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants