当我运行时,我的 Nextcloud 的 webpack 出现问题npm test
...
我的 webpack 版本
$ ./node_modules/.bin/webpack --version
webpack: 5.69.1
webpack-cli: 4.9.2
webpack-dev-server 4.7.4
包.json
{
"name": "workspace",
"version": "1.0.0",
"description": "Place this app in **nextcloud/apps/**",
"main": "main.js",
"private": true,
"scripts": {
"build": "webpack --node-env production --progress",
"dev": "webpack --node-env development --progress",
"watch": "webpack --node-env development --progress --watch",
"serve": "webpack --node-env development serve --progress",
"test": "NODE_ENV=testing mochapack --webpack-config webpack.test.config.js --require \"src/tests/OC.js\" \"src/tests/**/*.js\"",
"lint": "eslint --ext .js,.vue src",
"stylelint": "stylelint css/*.css css/*.scss src/**/*.vue",
"stylelint:fix": "stylelint css/*.css css/*.scss src/**/*.vue --fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/arawa/workspace.git"
},
"keywords": [],
"author": "Arawa <https://www.arawa.fr/>",
"contributors": [
{
"name": "Baptiste Fotia",
"email": "baptiste.fotia@arawa.fr"
},
{
"name": "Cyrille Bollu",
"email": "cyrille@bollu.be"
}
],
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/arawa/workspace/issues"
},
"homepage": "https://github.com/arawa/workspace#readme",
"engines": {
"npm": "^7.0.0",
"node": "^14.0.0"
},
"browserslist": [
"extends @nextcloud/browserslist-config"
],
"Comments": {
"devDependencies": [
"The @nextcloud/eslint-config's version 7.0.2 triggers a problem when we run `npm install`.",
"We must define the `--force` flag to install these devDependencies.",
"But, when we run `npm test`, we have an error on the conflicts on the eslint package as peerDependency.",
"I created an issue on this : https://github.com/nextcloud/eslint-config/issues/294.",
"One solutions is downgraded theses packages :",
"- @nextcloud/eslint-config@6.1.2",
"- @nextcloud/webpack-vue-config@3.1.10",
"Note: Look at this issue for webpack-vue-config package: https://github.com/nextcloud/nextcloud-vue/issues/2478"
]
},
"devDependencies": {
"@nextcloud/babel-config": "^1.0.0",
"@nextcloud/browserslist-config": "^2.2.0",
"@nextcloud/eslint-config": "^7.0.2",
"@nextcloud/stylelint-config": "^2.1.2",
"@nextcloud/webpack-vue-config": "^4.3.2",
"@vue/test-utils": "^1.3.0",
"chai": "^4.3.6",
"jsdom": "^19.0.0",
"jsdom-global": "^3.0.2",
"mochapack": "^2.1.4",
"prettier": "^2.5.1",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@nextcloud/axios": "^1.9.0",
"@nextcloud/l10n": "^1.4.1",
"@nextcloud/router": "^1.2.0",
"@nextcloud/vue": "^4.3.0",
"ramda": "^0.28.0",
"vue": "^2.6.12",
"vue-notification": "^1.3.20",
"vue-router": "^3.5.3",
"vuex": "^3.6.2"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
}
}
webpack.test.config.js
/**
* @copyright Copyright (c) 2017 Arawa
*
* @author 2021 Baptiste Fotia <baptiste.fotia@arawa.fr>
* @author 2021 Cyrille Bollu <cyrille@bollu.be>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable node/no-extraneous-require */
const path = require('path')
const { merge } = require('webpack-merge')
const webpackConfig = require('@nextcloud/webpack-vue-config')
const nodeExternals = require('webpack-node-externals')
require('jsdom-global')('', {
url: 'http://localhost',
})
const appName = process.env.npm_package_name
const config = merge(webpackConfig, {
mode: 'development',
devtool: 'inline-cheap-module-source-map',
externals: [nodeExternals()],
// Overrides the output config provided by Nextcloud as for some reason
// contenthash doesn't get appended to filenames
output: {
path: path.resolve('./js'),
publicPath: '/js/',
filename: `${appName}-[name].js`,
chunkFilename: `${appName}-[name].js`,
},
})
module.exports = config
问题
当我运行npm test
ornpm run test
时,我收到此错误:
$ npm run test
> workspace@1.0.0 test
> NODE_ENV=testing mochapack --webpack-config webpack.test.config.js --require "src/tests/OC.js" "src/tests/**/*.js"
Building workspace 1.0.0
[ ] 0% () WEBPACK Compiling...
[=== ] 10% (building)Download the Vue Devtools extension for a better development experience:
https://github.com/vuejs/vue-devtools
You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
[=========================] 98% (emitting) WEBPACK Failed to compile with 2 error(s)
Error
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 'http://localhost/eslintrc.cjs'
Error
The URL must be of scheme file
[=========================] 100% (completed)
但是,如果我将filename:
${appName}-[name].js,
替换为filename: path.resolve(
/js/${appName}-[name].js ),
,我会收到以下错误消息:
$ npm run test
> workspace@1.0.0 test
> NODE_ENV=testing mochapack --webpack-config webpack.test.config.js --require "src/tests/OC.js" "src/tests/**/*.js"
Building workspace 1.0.0
ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.output.filename: A relative path is expected. However, the provided value "/js/workspace-[name].js" is an absolute path!
Please use output.path to specify absolute path and output.filename for the file name.
at validate (/home/zak/Documents/arawa/codes/workspace/node_modules/webpack/node_modules/schema-utils/dist/validate.js:105:11)
at validateSchema (/home/zak/Documents/arawa/codes/workspace/node_modules/webpack/lib/validateSchema.js:78:2)
at create (/home/zak/Documents/arawa/codes/workspace/node_modules/webpack/lib/webpack.js:111:24)
at webpack (/home/zak/Documents/arawa/codes/workspace/node_modules/webpack/lib/webpack.js:158:32)
at Object.f [as default] (/home/zak/Documents/arawa/codes/workspace/node_modules/webpack/lib/index.js:63:16)
at Object.createCompiler [as default] (/home/zak/Documents/arawa/codes/workspace/node_modules/mochapack/lib/webpack/compiler/createCompiler.js:8:40)
at TestRunner.<anonymous> (/home/zak/Documents/arawa/codes/workspace/node_modules/mochapack/lib/runner/TestRunner.js:130:63)
at step (/home/zak/Documents/arawa/codes/workspace/node_modules/mochapack/lib/runner/TestRunner.js:46:23)
at Object.next (/home/zak/Documents/arawa/codes/workspace/node_modules/mochapack/lib/runner/TestRunner.js:27:53)
at fulfilled (/home/zak/Documents/arawa/codes/workspace/node_modules/mochapack/lib/runner/TestRunner.js:18:58)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
它要求我不要放置绝对路径,但它也要求我放置绝对路径......所以,我不明白这里的问题出在哪里:/