我是一个新手,对Webpack、Node.js和Typescript不熟悉,我在配置开发环境时遇到了问题。
当我运行
项目的架构是:
当我运行
webpack
编译src/server.ts
以生成/server/bundle.js
时,出现了以下错误:ERROR in ./src/server.ts
Module not found: Error: Can't resolve 'hapi' in '/Volumes/Dados/giovane/dev/studio-hikari/nodang/nodang-api/src'
@ ./src/server.ts 3:11-26
项目的架构是:
src/server.ts
文件:
import * as Hapi from 'hapi';
const server = new Hapi.Server();
webpack.config.js
:
const path = require('path');
module.exports = {
entry: './src/server.ts',
output: {
filename: './server/bundle.js'
},
resolve: {
extensions: ['.ts'],
modules: [
path.resolve('src'),
path.resolve('node_modules')
]
},
module: {
loaders: [
{
test: /.ts$/,
loader: 'awesome-typescript-loader'
}
]
}
};
package.json
文件:
{
"name": "nodang-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "webpack --progress --watch",
"serve": "node-dev server/bundle.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/hapi": "^16.0.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"awesome-typescript-loader": "^3.0.8",
"tsd": "^0.6.5",
"typescript": "^2.2.1",
"webpack": "^2.2.1"
}
}
OBS:这是webpack 2
更新
安装hapi
后,将.js
添加到webpack的解析扩展名中,并将node
设置为webpack的目标后,我在使用hapi模块时遇到了以下错误:
ERROR in ./~/hapi/lib/server.js
Module not found: Error: Can't resolve 'catbox' in '/Volumes/Dados/giovane/dev/studio-hikari/nodang/nodang-api/node_modules/hapi/lib'
@ ./~/hapi/lib/server.js 5:15-32
@ ./~/hapi/lib/index.js
@ ./src/server.ts
ERROR in ./~/hapi/lib/server.js
Module not found: Error: Can't resolve 'catbox-memory' in '/Volumes/Dados/giovane/dev/studio-hikari/nodang/nodang-api/node_modules/hapi/lib'
@ ./~/hapi/lib/server.js 6:21-45
@ ./~/hapi/lib/index.js
@ ./src/server.ts
test: /\.ts$/,
may be you would escape the.
- Jai