- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下目录结构:
- webpack.config.js
- 来源
- 索引.js
-距离
- 索引.js
一个 webpack 配置:
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 中导入请求(const request = require('request');
),我会从 node_modules 中收到错误。
我怎样才能避免这种情况?我以为我已经排除了 node_modules。
只是为了完成我的 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"
}
}
最佳答案
您没有排除 node_modules
,因为 __dirname
不包含尾部斜线。尝试使用 path.resolve
:
const path = require('path');
module.exports = {
module: {
loaders: [{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
exclude: path.resolve(__dirname, 'node_modules'),
loader: "babel-loader"
}],
},
// ...
}
关于javascript - Webpack 不排除 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34609437/
我已经创建了自己的 npm 包,我们称它为 XYZ,它在 package.json 文件中具有 @material-ui 依赖项。 当我在项目 A 中安装它时,我在 XYZ 文件夹中嵌套了 node_
我遇到过这样一种情况:node_modules/@types 中的类型定义正在安装它自己的@types 依赖项,而这些“嵌套”@types 与我的顶级@types 冲突。 @types |-angul
当我 npm start 时出现此错误我的 react 项目。谁能解决这个问题? ./src/index.scss (./node_modules/css-loader/dist/cjs.js??re
我正在尝试使用 CopyWebpackPlugin 将一些文件从我的 node_modules 文件夹复制到我的构建文件夹中。 new CopyWebpackPlugin([ { from: 'n
我正在尝试使用 CopyWebpackPlugin 将一些文件从我的 node_modules 文件夹复制到我的构建文件夹中。 new CopyWebpackPlugin([ { from: 'n
我正在将一个项目从使用 Grunt 迁移到使用 Webpack。这个项目使用 jQuery。我注意到捆绑代码工作正常,即使我还没有将 jQuery 添加到 package.json,这看起来很奇怪。
当我在本地安装时,将我的模块两个父项放在我的项目文件夹之上。为什么会这样? 谢谢! 最佳答案 手动将 node_modules 文件夹扔进去就可以了 关于javascript - npm 在../..
我遇到了这个问题..有人有想法..那是什么意思.?想在我的本地机器上启动我的应用程序。但医生的工作方式。我在这里用模块或注释和 bcrypt 卡住?有人有解决这个问题的想法吗?为什么会出现这个问题。?
我最近发现了 ack 和 ack -ir --ignore-dir={node_modules,dist,.git} 对大多数事情都很好,但是这个 ---node_modules/ ---------
我在部署 netlify 时遇到问题,有些冲突我不明白。我尝试清除缓存、重建基础、重建包、在 netlify 上重新部署、重新安装 mini-CSS-extract-plugin。 调试 Netlif
我是 NodeJS 的新手,想使用 Sequelize。 我在新的 CentOS7 虚拟机上安装了 PostgreSQL 和 Node。 node -v v10.14.1 npm -v v6.5.0
我安装了 npm,当我第一次执行 sudo npm install some-package -g 时,它按照我的预期将该包安装到/usr/lib/node_modules,但随后它还在~/.npm。
我刚刚创建了一个带有“验证器”依赖项的 Node 模块。但是当我从 npm 安装它时,它不会在它自己的 node_module 目录中安装“验证器”模块。我不明白为什么,但这是我第一次创建自己的 No
我正在尝试使用 npm install packagename 将软件包安装到项目中.然后安装继续安装到 /home/myusername/node_modules/packagename/node_
我正在尝试构建我的 angular 项目并出现以下错误: Build Command: node --max_old_space_size=8192 node_modules/@angular/cli
我正在通过自制软件安装星舰,但出现此错误: Permission denied @ apply2files - /usr/local/lib/node_modules/expo-cli/node_mo
我试图在 Windows 10 中运行一个 Angular 项目。这与我在 Ubuntu 中执行的项目相同。当我克隆存储库并安装所有 Node 包时,我遇到了这个错误。 ERROR in./node_
我跑npm init npm i -D jest像这样 tutorial 运行推荐 nmp test 后出现此错误 这不是生物.js 或生物.test.js 的错误,因为没有发生此文件错误。我怎样才能
我刚刚将 npm 更新到 5.4.0。 现在,每当我想安装 npm 包时,我都会收到以下错误: D:\Sources\DownloadCms\Md.Download\Web.Angular>npm i
我正在尝试使用 npm 命令安装 appium。 每次尝试我都会遇到错误。 在最后一次尝试中,我引用了以下链接: node-gyp build error windows x64 为了在我的 Wind
我是一名优秀的程序员,十分优秀!