bholloway / resolve-url-loader

Webpack loader that resolves relative paths in url() statements based on the original source file
563 stars 71 forks source link

Module build failed: ReferenceError: document is not defined #38

Closed folmert closed 7 years ago

folmert commented 7 years ago

When I run webpack it returns:

ERROR in ./~/css-loader!./~/resolve-url/resolve-url.js!./~/sass-loader?sourceMap!./~/bootstrap-loader/lib/bootstrap.styles.loader.js!./~/bootstrap-loader/n
o-op.js
    Module build failed: ReferenceError: document is not defined
        at Object.resolveUrl (C:\sites\YDR\branches\refactoring\development\node_modules\resolve-url\resolve-url.js:21:16)
     @ ./~/bootstrap-loader/lib/bootstrap.loader.js!./~/bootstrap-loader/no-op.js 1:21-122
     @ ./~/bootstrap-loader/loader.js
     @ ./app/static/js/app.js
     @ multi main

My package.json:

{
  "name": "new-admin",
  "version": "1.0.0",
  "description": "",
  "main": "0.44132ff81411f73136a6.hot-update.js",
  "dependencies": {
    "autoprefixer": "^6.5.3",
    "babel": "^6.5.2",
    "babel-loader": "^6.2.8",
    "bootstrap": "^3.3.7",
    "bootstrap-loader": "^2.0.0-beta.16",
    "css-loader": "^0.26.0",
    "file-loader": "^0.9.0",
    "jquery": "^3.1.1",
    "postcss": "^5.2.5",
    "postcss-loader": "^1.1.1",
    "sass-loader": "^4.0.2",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "webpack": "^2.1.0-beta.27",
    "webpack-dev-server": "^1.16.2",
    "webpack-uglify-js-plugin": "^1.1.9"
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-preset-es2015": "^6.18.0",
    "bootstrap-loader": "^2.0.0-beta.16",
    "bootstrap-sass": "^3.3.7",
    "postcss-import": "^8.2.0",
    "postcss-load-config": "^1.0.0",
    "postcss-loader": "^1.1.1",
    "precss": "^1.4.0"
  },
  "scripts": {},
  "author": "",
  "license": "ISC"
}
folmert commented 7 years ago

Strange, but the error is gone when I updated bootstrap-loader to newest version: npm install --save-dev bootstrap-loader@2.0.0-beta.16

bholloway commented 7 years ago

I don't see this project as a loader in your package.json

What about your webpack config?

emri99 commented 7 years ago

Hello, got same issue.

I think that using document in node context should (normally) fail.

When installing via npm i resolve-url-loader, I've got this error (this could be related to my own project as I already got this message earlier):

 UNMET PEER DEPENDENCY jsdom@*

Not sure this is the fix, but installing jsdom fix this issue and gave me what I want ! Shouldn't jsdom (or any other module providing DOM usage in node) be included in your project dependencies ?

Anyway, thx for this loader, it's save me from url path headaches !

bholloway commented 7 years ago

This is completely unrelated.

The original project posted didn't use resolve-url-loader.

The file mentioned is in a package called resolve-url. Different package.

Never omit the loader suffix when specifying webpack loaders. This may be the problem. I should update the usage docs if they imply that.

emri99 commented 7 years ago

Apologize, you're right ! Thanks for pointing this out ;)

Indeed, updating docs makes sense, I think

bholloway commented 7 years ago

No problem @emri99.

Webpack is such a steep curve. I hope you get your project happy soon. It is super cool to have build and fingerprinting and Webpack 'all the things'.