Javascript 网页包不是';t不包括节点_模块

Javascript 网页包不是';t不包括节点_模块,javascript,webpack,ecmascript-6,Javascript,Webpack,Ecmascript 6,我有以下目录结构: -webpack.config.js -src -index.js -距离 -index.js 网页包配置: module.exports = { module: { loaders: [{ test: /\.js$/, include: __dirname + 'src', exclude: __dirname + 'node_modules', loader: "babel-loade

我有以下目录结构:


-webpack.config.js
-src
-index.js
-距离
-index.js

网页包配置:

module.exports = {
    module: {
      loaders: [{
        test: /\.js$/,
        include: __dirname + 'src',
        exclude: __dirname + 'node_modules',
        loader: "babel-loader"
      }],
    },
    resolve: {
      extensions: ['.js']
    },
    output: {
      path: __dirname + '/dist',
      filename: 'index.js'
    }
};
但是,如果我在src/index.js(
constrequest=require('request');
)中导入请求,我将从node_模块中获得错误

我怎样才能避免这种情况?我想我已经排除了node_模块

仅为了完成my package.json:

{
  "name": "leo-trans",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "watch": "webpack --watch",
    "start": "node dist/index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "preferGlobal": true,
  "bin": {
    "leo-trans": "./dist/index.js"
  },
  "devDependencies": {
    "babel-core": "^6.3.26",
    "babel-loader": "^6.2.1"
  },
  "dependencies": {
    "cheerio": "^0.19.0",
    "request": "^2.67.0"
  }
}

您没有排除
节点\u模块
,因为
\u目录名
不包含尾随斜杠。尝试使用:

const path=require('path');
module.exports={
模块:{
装载机:[{
测试:/\.js$/,,
包括:path.resolve(uu dirname,'src'),
排除:path.resolve(uu dirname,'node_modules'),
加载器:“巴别塔加载器”
}],
},
// ...
}

这是固定的,但当我想在我的一个js文件中导入npm包时,仍然会出现错误。类似的情况,还有许多其他模块。/~/htmlparser2/~/entities/maps/decode.json模块解析失败:/home/maex/projects/leo trans/node_modules/htmlparser2/node_modules/entities/maps/decode.json第1行错误:意外标记:您可能需要一个合适的加载程序来处理此文件类型。@mstruebing我已更新了答案。尝试使用path.resolve