Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Using npm alternative and node6 break the build #186

Closed
pandada8 opened this issue May 16, 2016 · 4 comments
Closed

Using npm alternative and node6 break the build #186

pandada8 opened this issue May 16, 2016 · 4 comments

Comments

@pandada8
Copy link

pandada8 commented May 16, 2016

webpack.config.js

var path = require('path')
var ExtractTextPlugin = require("extract-text-webpack-plugin")

module.exports = {
  entry: './main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'app.js'
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract("style-loader", "css-loader")
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("app.css")
  ],
}

main.js

require("./main.css")

main.css

html{}

when using node6, if modules was installed from npm alternatives (eg: https://github.com/cnpm/npminstall, https://github.com/alexanderGugel/ied, which using symlink to save disk space and time) result in following error.

ERROR in ./main.css
Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example
    at Object.module.exports.pitch (/private/tmp/example/node_modules/.npminstall/extract-text-webpack-plugin/1.0.1/extract-text-webpack-plugin/loader.js:21:9)
 @ ./main.js 1:0-18

which works well in the node5.11.1, and using original npm with node 6 works well too.

@imcamo
Copy link

imcamo commented May 19, 2016

Please install the nodejs version management tool NVM and switch the version to 5.0.0。
1.install NVM

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash

2.Install the version you need

nvm install [Nodejs version]

3.Switch version

nvm use [Nodejs version]

@pandada8
Copy link
Author

pandada8 commented May 19, 2016

@camoth yeh, I know node5 with npminstall works well.
but node6 with npminstall did break the build.

It seems extract-text-webpack-plugin using __dirname to identify if plugin is properly configured. Have node changed the way handling __dirname in symlinked js ?

@pandada8
Copy link
Author

pandada8 commented May 19, 2016

after doing some logging and diff stuff I found that in the pitch loader , original this[__dirname] function is being placed in a different location

-[log] /private/tmp/test/node_modules/.npminstall/extract-text-webpack-plugin/1.0.1/extract-text-webpack-plugin function (content, opt) {
+[log] /private/tmp/test/node_modules/extract-text-webpack-plugin function (content, opt) {

I am not familiar with webpack plugin development, but it seems node6 changed just to not resolve the symlink? Maybe this is a webpack side issue ?

@pandada8
Copy link
Author

OK, it seems the root cause is node changed the way handling symlink in nodejs/node#5950, which resolve imported modules' __dirname as the symlinked path. This change is actually reverted in node 6.2, so for anyone having this issue, just upgrade your node version.

I decided just to close this issue, cuz there is nothing wrong with the extract-text-webpack-plugin. Sorry for the noise !

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

No branches or pull requests

2 participants