模块解析失败:关于手写笔文件的意外令牌(2:11)

时间:2018-02-04 03:40:54

标签: webpack vue.js stylus webpack.config.js

我使用Vue.js在浏览器中出现以下错误:

Failed to compile.

./src/assets/styles/global.styl
Module parse failed: Unexpected token (2:11)
You may need an appropriate loader to handle this file type.
| 
| html, body {
|   margin: 0
|   padding: 0
 @ ./src/main.js 4:0-37
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8081 webpack/hot/dev-server ./src/main.js

在我的webpack.config.js - > module - > rules,这是我的.styl文件的配置:

{
    test: /\.styl$/,
    use: [
      'style-loader',
      'css-loader',
      {
        loader: 'postcss-loader',
        options: {
          sourceMap: true,   
        }
      },
      'stylus-loader'
    ],
  },

我的代码global.styl如下:

html, body {
  margin: 0
  padding: 0
  width: 100%
  height: 100%
}

body {
  background-image url("../imgs/01.jpg")
  background-size: cover
  background-position: center
  font: 14px 'Helvetica Neue'
  font-weight: 300
}

1 个答案:

答案 0 :(得分:1)

您已在'stylus-loader'模块规则中配置webpack.config.js,但仍会收到错误消息。

多数人应该是你没有将stylus-loader安装到node_modules

安装stylusstylus-loader

npm i stylus@>=0.52.4 stylus-loader

和restrat pnm run dev