Я использую webpack и babel для создания приложения с использованием синтаксиса ES6. Проблема в том, что я не могу импортировать express
.
(Примечание: я могу импортировать (и требовать) модуль узла «путь», больше не проверял)
Вот мое приложение:
import express from 'express';
Даже приведенное ниже приводит к той же ошибке:
var app = require('express');
Вот мой webpack.config.js
module.exports = {
entry: './src/app.js',
output: {
path: 'builds',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js/,
loader: 'babel',
include: __dirname + '/src',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}
],
}
};
Я также пробовал следующее:
exclude: [/node_modules/],
exclude: __dirname + '/node_modules',
Но я все еще продолжаю получать очень большую трассировку стека, которая начинается с:
WARNING in ./~/express/lib/view.js
Critical dependencies:
78:29-56 the request of a dependency is an expression
@ ./~/express/lib/view.js 78:29-56
ERROR in ./~/express/lib/request.js
Module not found: Error: Cannot resolve module 'net' in /home/projects/node_modules/express/lib
@ ./~/express/lib/request.js 18:11-25
ERROR in ./~/express/lib/view.js
Module not found: Error: Cannot resolve module 'fs' in /home/projects/node_modules/express/lib
@ ./~/express/lib/view.js 18:9-22
И заканчивается
@ ./~/mime/mime.js 87:12-35
ERROR in ./~/mime-db/db.json
Module parse failed: /home/projects/node_modules/mime-db/db.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "application/1d-interleaved-parityfec": {
| "source": "iana"
| },
@ ./~/mime-db/index.js 11:17-37
Я думаю, это потому, что папка node_modules
не игнорируется?
Также это мой package.json
, если, возможно, версии модуля являются проблемой:
{
"name": "testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.13.4"
},
"devDependencies": {
"babel-core": "^6.6.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"webpack": "^1.12.14"
}
}
Can't resolve 'fs'
иCan't resolve 'net'
- person Enrique Moreno Tent   schedule 14.08.2017