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

Cannot read property 'split' of undefined #156

Closed
paulius005 opened this issue May 21, 2018 · 17 comments
Closed

Cannot read property 'split' of undefined #156

paulius005 opened this issue May 21, 2018 · 17 comments

Comments

@paulius005
Copy link

I seem to be getting Cannot read property 'split' of undefined on ubuntu 14.04 on node 8

Here is the config:

{
    test: /\.css$/,
    use:  [{
      loader:  MiniCssExtractPlugin.loader,
      options: {
        root: path.join(__dirname, '../..')
      }
    }, {
      loader:  'postcss-loader',
      options: { config: { path: POSTCSS_PATH } }
    }]
  }

Here is the output:

�[91m/usr/local/loom/node_modules/mini-css-extract-plugin/dist/index.js:81
    const resource = this._identifier.split('!').pop();
                                      ^

TypeError: Cannot read property 'split' of undefined
    at CssModule.nameForCondition (/usr/local/loom/node_modules/mini-css-extract-plugin/dist/index.js:81:39)
    at Function.checkTest (/usr/local/loom/node_modules/webpack/lib/optimize/SplitChunksPlugin.js:255:52)
    at Object.fn [as getCacheGroups] (/usr/local/loom/node_modules/webpack/lib/optimize/SplitChunksPlugin.js:209:35)
    at compilation.hooks.optimizeChunksAdvanced.tap.chunks (/usr/local/loom/node_modules/webpack/lib/optimize/SplitChunksPlugin.js:361:38)
    at SyncBailHook.eval (eval at create (/usr/local/loom/node_modules/tapable/lib/HookCodeFactory.js:17:12), <anonymous>:12:16)
    at SyncBailHook.lazyCompileHook [as _call] (/usr/local/loom/node_modules/tapable/lib/Hook.js:35:21)
    at Compilation.seal (/usr/local/loom/node_modules/webpack/lib/Compilation.js:884:38)
    at hooks.make.callAsync.err (/usr/local/loom/node_modules/webpack/lib/Compiler.js:481:17)
    at _done (eval at create (/usr/local/loom/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:9:1)
    at _err30 (eval at create (/usr/local/loom/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:380:22)
    at _addModuleChain (/usr/local/loom/node_modules/webpack/lib/Compilation.js:758:12)
    at processModuleDependencies.err (/usr/local/loom/node_modules/webpack/lib/Compilation.js:697:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Do you see anything wrong with the config?

Between not being able to use https://github.com/webpack-contrib/extract-text-webpack-plugin and this error, it seems that upgrading to webpack 4 is not happening if one wants to take out their css into separate files

@alexander-akait
Copy link
Member

@paulius005 can you create minimum reproducible test repo?

@alexander-akait
Copy link
Member

@paulius005 you missing css-loader in your configuration, mini-css-extract-plugin only for extract css

@ckotzbauer
Copy link

@evilebottnawi That are really bad news... I've got the same exception.

In my project we're loading css and scss files with the raw-loader instead of the css-loader. The reason for this is, that not all images, fonts and other resources can be resolved from webpack due to dynamic bindings in html. (Since there's no option in the css-loader to avoid resolving of those files) This would result in a mix of automatically handled resources from the css-loader and some manually handled from us. I want to avoid that.

This means (with extract-text-webpack-plugin deprecation in mind) that there will be no future-safe solution for projects like ours which differs from default css-setup with css-loader??

If the css-loader is a requirement for this plugin, then it should be noted in the docs.

@knynkwl
Copy link

knynkwl commented May 30, 2018

@code-chris this setup worked for me:

rules: [{
    test: /\.css$/,
    use: [
      MiniCssExtractPlugin.loader,
      {
        loader: 'css-loader',
        options: {
          importLoaders: 1,
          minimize: PROD ? true : false
        }
      },
      {
        loader: 'postcss-loader',
        options: config.postcss,
      }
    ]
  }]

@vasiliy-s
Copy link

@code-chris
you can use 'css-loader?url=false'

@itsmelion
Copy link

TL;DR: Mind the Loaders order of execution. Leave MiniCss right after the css-loader;

I was having the same issue, but ive found the solution.
ive setup, a stack of loaders in the following order:

Before
MiniCssExtractPlugin.loader!clean-css-loader!css-loader!postcss-loader!resolve-url-loader!sass-loader

notice CleanCss Loader was between MiniCss, and css-loader, and this was causing the bug.
i got it fixed when i placed it between css-loader and postcss-loader

After
MiniCssExtractPlugin.loader!css-loader!clean-css-loader!postcss-loader!resolve-url-loader!sass-loader

@iiison
Copy link

iiison commented May 13, 2019

I had the same issue today, after long research, I found that you will get the same error if exportOnlyLocals in css-loader options is set to true. I don't know the exact reason for it, but it causes the error.

@alexander-akait
Copy link
Member

Somebody can create minimum reproducible test repo?

@Tofandel
Copy link

You can just create a vue cli project and in vue.config.js add this

module.exports = {
    css: {
        extract: true,
        loaderOptions: {
            css: {
                onlyLocals: true
            }
        }
    },

And you will get the issue

@fredski02
Copy link

bump, experiencing this issue also when using onlyLocals : true

@jamesho2877
Copy link

jamesho2877 commented Mar 19, 2020

Me too, with onlyLocals : true enabled to kindly support css modules.
Anyone who ran into this issue with other reasons than missing css-loader, then here is the one you may want to have a look.

@KirillYoYo

This comment has been minimized.

@arcanis
Copy link

arcanis commented Sep 24, 2020

I'm not sure why @KirillYoYo's comment was marked as spam, but downgrading the css-loader version did fix the crash in my case.

@alexander-akait
Copy link
Member

@arcanis Can you create reproducible test repo and open new issue?

@alexander-akait
Copy link
Member

@arcanis Do you use onlyLocals or exportOnlyLocals?

@linguamatics-albert
Copy link

linguamatics-albert commented Sep 25, 2020

Dunno if it matters in this case but as an additional input I got the same error after doing a npm install css-loader. This downloaded the version "css-loader": "^4.3.0" and made this error to start appearing.

The way how I fixed is just reverting css-loder to it's previous version (I believe installed by node_modules/@vue/cli-service as a package dependency?), that in my case is "version": "1.0.1".

In my case I'm using vue-cli services 3.3.1

I however understand that other people might not be able to revert their dependencies or use an old version of css-loader.

@ashvin777
Copy link

Reverting back to the older version of css-loader fixed this issue for me

npm install --save-dev css-loader@2.1.1

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