最初,fs
尽管已安装,却无法找到。
This dependency was not found: fs in ./node_modules/emailjs/smtp/message.js
根据this similar question,应通过在target: 'node'
上添加webpack.config.js
来解决该问题。我已经将the Nuxt.js
way中的配置插入到nuxt.config.js
中,({我认为),但是会产生以下错误:
WebpackOptionsValidationError: Invalid configuration object.
Webpack has been initialised using a configuration object that
does not match the API schema.
- configuration.module.rules[10] has an unknown property 'target'.
These properties are valid: object { enforce?, exclude?, include?,
issuer?, loader?, loaders?, oneOf?, options?, parser?, query?,
resource?, resourceQuery?, compiler?, rules?, test?, use? }
这是否意味着当前不可能?
nuxt.config.js
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient }) {
config.module.rules.push({target: 'node'}) // <-- Added this
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
investment.vue
export default {
asyncData ( context ) {
let email = require('../node_modules/emailjs/email');
console.log('process.server', process.server); // Evalutes to true
}
};
package.json
"dependencies": {
"emailjs": "^2.2.0",
"fs": "^0.0.1-security",
"net": "^1.0.2",
"nuxt": "^1.0.0",
"tls": "^0.0.1"
},
答案 0 :(得分:2)
Nuxt代码分为客户端部分和服务器部分。您尝试在组件中使用库emailjs
,这是客户端。它无法访问fs
库(在Web中)。您需要在服务器部分(例如在为您的页面提供服务的express
服务器上)上编写它。