Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack Aurelia:错误:尝试注册已存在同名元素的元素。姓名:n.-仅在生产Web包生成中发生_Webpack_Aurelia - Fatal编程技术网

Webpack Aurelia:错误:尝试注册已存在同名元素的元素。姓名:n.-仅在生产Web包生成中发生

Webpack Aurelia:错误:尝试注册已存在同名元素的元素。姓名:n.-仅在生产Web包生成中发生,webpack,aurelia,Webpack,Aurelia,最近,我将我的网页构建拆分为单独的配置文件,并将它们与公共配置文件合并 除了模式之外,配置之间的唯一区别是全局定义的基本URL const merge = require('webpack-merge'); const common = require('./webpack.common.js'); const DefinePlugin = require('webpack').DefinePlugin; module.exports = merge(common, { mode: 'd

最近,我将我的网页构建拆分为单独的配置文件,并将它们与公共配置文件合并

除了
模式
之外,配置之间的唯一区别是全局定义的
基本URL

const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const DefinePlugin = require('webpack').DefinePlugin;
module.exports = merge(common, {
    mode: 'development',
    devtool: 'inline-source-map',
    plugins: [
        new DefinePlugin({
            BASE_URL: JSON.stringify('http://localhost:5000')
        })
    ]
})
在此之前,我使用了单个webpack.config和CLI中的
--mode production
选项

在我的代码中,我可以在两个bundle中看到正确的
BASE\u URL
,但只有
开发
一个有效;另一个抛出错误:
error:当同名元素已经存在时,尝试注册该元素。Name:n.
这非常没有帮助,因为我没有名为
n
的元素

编辑:在自动注册全局资源的过程中出现错误,特别是对于此my
DateFormat
值转换器:

date-format.ts

export class DateFormatValueConverter {
    toView(value: string) {
        return new Date(value).toLocaleString();
    }
}
索引

import { FrameworkConfiguration } from 'aurelia-framework';
import { DateInputFormatValueConverter } from './value-converters/date-input-format';
import { DateFormatValueConverter } from './value-converters/date-format';

export function configure(config: FrameworkConfiguration) {
    config.globalResources(
        [
            DateInputFormatValueConverter,
            DateFormatValueConverter
        ]
    )
}
EDIT2:除了第一个条目外,它似乎是任何全局资源

EDIT3:如果我通过字符串声明全局资源(并且
PLATFORM.moduleName
)可以工作。这可能是奥雷利亚团队应该调查的事情

export function configure(config: FrameworkConfiguration) {
    config.globalResources(
        [
            PLATFORM.moduleName('./value-converters/date-input-format'),
            PLATFORM.moduleName('./value-converters/date-format'),
            PLATFORM.moduleName('./value-converters/delay-format'),
            ...
        ]
    )
}

原因是类名被拼成了1-2个字母。像这样:

export class DatePicker {}
// turned into
// when inspecting the class for static resources declaration, name of the resource will be "n"
let n = class{}
exports.DatePicker = n;
解决方法是给他们明确的名字:

// either
@customElement('date-picker')
// or
export class DatePicker {
  static $resource = {
    name: 'date-picker',
    type: 'element'
  }
  // if it's custom element, no need to specify type
  static $resource = 'date-picker';
}

谢谢我会尝试一下,一旦验证,我会接受答案!