我的一个文件导入了。在beta.25中,它返回了正确的对象,但在2.2中它返回undefined和一个疯狂的默认值。
我一直在使用webpack 2.1.0-beta.25并升级到2.2.0版本。我已经降级回2.1.0-beta.28并且工作正常。第二个我切换到2.2.0+,它打破了。
控制台输出版本beta.25:
Object{CENTER: 'CENTER', LEFT: 'LEFT', RIGHT: 'RIGHT'}, Object{Align: Object{CENTER: 'CENTER', LEFT: 'LEFT', RIGHT: 'RIGHT'}, SortingDirection: Object{ASC: 'ASCENDING', DESC: 'DESCENDING'}}
控制台输出版本2.2.0:
undefined, Object{O_RDONLY: 0, O_WRONLY: 1, O_RDWR: 2, S_IFMT: 61440, S_IFREG: 32768, S_IFDIR: 16384, S_IFCHR: 8192, S_IFBLK: 24576, S_IFIFO: 4096, S_IFLNK: 40960, S_IFSOCK: 49152, O_CREAT: 512, O_EXCL: 2048, O_NOCTTY: 131072, O_TRUNC: 1024, O_APPEND: 8, O_DIRECTORY: 1048576, O_NOFOLLOW: 256, O_SYNC: 128, O_SYMLINK: 2097152, O_NONBLOCK: 4, S_IRWXU: 448, S_IRUSR: 256, S_IWUSR: 128, S_IXUSR: 64, S_IRWXG: 56, S_IRGRP: 32, S_IWGRP: 16, S_IXGRP: 8, S_IRWXO: 7, S_IROTH: 4, S_IWOTH: 2, S_IXOTH: 1, E2BIG: 7, EACCES: 13, EADDRINUSE: 48, EADDRNOTAVAIL: 49, EAFNOSUPPORT: 47, EAGAIN: 35, EALREADY: 37, EBADF: 9, EBADMSG: 94, EBUSY: 16, ECANCELED: 89, ECHILD: 10, ECONNABORTED: 53, ECONNREFUSED: 61, ECONNRESET: 54, EDEADLK: 11, EDESTADDRREQ: 39, EDOM: 33, EDQUOT: 69, EEXIST: 17, EFAULT: 14, EFBIG: 27, EHOSTUNREACH: 65, EIDRM: 90, EILSEQ: 92, EINPROGRESS: 36, EINTR: 4, EINVAL: 22, EIO: 5, EISCONN: 56, EISDIR: 21, ELOOP: 62, EMFILE: 24, EMLINK: 31, EMSGSIZE: 40, EMULTIHOP: 95, ENAMETOOLONG: 63, ENETDOWN: 50, ENETRESET: 52, ENETUNREACH: 51, ENFILE: 23, ENOBUFS: 55, ENODATA: 96, ENODEV: 19, ENOENT: 2, ENOEXEC: 8, ENOLCK: 77, ENOLINK: 97, ENOMEM: 12, ENOMSG: 91, ENOPROTOOPT: 42, ENOSPC: 28, ENOSR: 98, ENOSTR: 99, ENOSYS: 78, ENOTCONN: 57, ENOTDIR: 20, ENOTEMPTY: 66, ENOTSOCK: 38, ENOTSUP: 45, ENOTTY: 25, ENXIO: 6, EOPNOTSUPP: 102, EOVERFLOW: 84, EPERM: 1, EPIPE: 32, EPROTO: 100, EPROTONOSUPPORT: 43, EPROTOTYPE: 41, ERANGE: 34, EROFS: 30, ESPIPE: 29, ESRCH: 3, ESTALE: 70, ETIME: 101, ETIMEDOUT: 60, ETXTBSY: 26, EWOULDBLOCK: 35, EXDEV: 18, SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGILL: 4, SIGTRAP: 5, SIGABRT: 6, SIGIOT: 6, SIGBUS: 10, SIGFPE: 8, SIGKILL: 9, SIGUSR1: 30, SIGSEGV: 11, SIGUSR2: 31, SIGPIPE: 13, SIGALRM: 14, SIGTERM: 15, SIGCHLD: 20, SIGCONT: 19, SIGSTOP: 17, SIGTSTP: 18, SIGTTIN: 21, SIGTTOU: 22, SIGURG: 16, SIGXCPU: 24, SIGXFSZ: 25, SIGVTALRM: 26, SIGPROF: 27, SIGWINCH: 28, SIGIO: 23, SIGSYS: 12, SSL_OP_ALL: 2147486719, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: 262144, SSL_OP_CIPHER_SERVER_PREFERENCE: 4194304, SSL_OP_CISCO_ANYCONNECT: 32768, SSL_OP_COOKIE_EXCHANGE: 8192, SSL_OP_CRYPTOPRO_TLSEXT_BUG: 2147483648, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: 2048, SSL_OP_EPHEMERAL_RSA: 0, SSL_OP_LEGACY_SERVER_CONNECT: 4, SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: 32, SSL_OP_MICROSOFT_SESS_ID_BUG: 1, SSL_OP_MSIE_SSLV2_RSA_PADDING: 0, SSL_OP_NETSCAPE_CA_DN_BUG: 536870912, SSL_OP_NETSCAPE_CHALLENGE_BUG: 2, SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: 1073741824, SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: 8, SSL_OP_NO_COMPRESSION: 131072, SSL_OP_NO_QUERY_MTU: 4096, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: 65536, SSL_OP_NO_SSLv2: 16777216, SSL_OP_NO_SSLv3: 33554432, SSL_OP_NO_TICKET: 16384, SSL_OP_NO_TLSv1: 67108864, SSL_OP_NO_TLSv1_1: 268435456, SSL_OP_NO_TLSv1_2: 134217728, SSL_OP_PKCS1_CHECK_1: 0, SSL_OP_PKCS1_CHECK_2: 0, SSL_OP_SINGLE_DH_USE: 1048576, SSL_OP_SINGLE_ECDH_USE: 524288, SSL_OP_SSLEAY_080_CLIENT_DH_BUG: 128, SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: 0, SSL_OP_TLS_BLOCK_PADDING_BUG: 512, SSL_OP_TLS_D5_BUG: 256, SSL_OP_TLS_ROLLBACK_BUG: 8388608, ENGINE_METHOD_DSA: 2, ENGINE_METHOD_DH: 4, ENGINE_METHOD_RAND: 8, ENGINE_METHOD_ECDH: 16, ENGINE_METHOD_ECDSA: 32, ENGINE_METHOD_CIPHERS: 64, ENGINE_METHOD_DIGESTS: 128, ENGINE_METHOD_STORE: 256, ENGINE_METHOD_PKEY_METHS: 512, ENGINE_METHOD_PKEY_ASN1_METHS: 1024, ENGINE_METHOD_ALL: 65535, ENGINE_METHOD_NONE: 0, DH_CHECK_P_NOT_SAFE_PRIME: 2, DH_CHECK_P_NOT_PRIME: 1, DH_UNABLE_TO_CHECK_GENERATOR: 4, DH_NOT_SUITABLE_GENERATOR: 8, NPN_ENABLED: 1, RSA_PKCS1_PADDING: 1, RSA_SSLV23_PADDING: 2, RSA_NO_PADDING: 3, RSA_PKCS1_OAEP_PADDING: 4, RSA_X931_PADDING: 5, RSA_PKCS1_PSS_PADDING: 6, POINT_CONVERSION_COMPRESSED: 2, POINT_CONVERSION_UNCOMPRESSED: 4, POINT_CONVERSION_HYBRID: 6, F_OK: 0, R_OK: 4, W_OK: 2, X_OK: 1, UV_UDP_REUSEADDR: 4}
导入:
import Constants, { Align as AlignConstant } from './constants';
console.log(AlignConstant, Constants);
constants.json:
export const Align = {
CENTER: 'CENTER',
LEFT: 'LEFT',
RIGHT: 'RIGHT',
};
export const SortingDirection = {
ASC: 'ASCENDING',
DESC: 'DESCENDING',
};
export default {
Align,
SortingDirection
};
karma.conf.js使用的webpack.test.config.js:
const path = require('path');
const webpack = require('webpack');
const modules = [
'packages',
'node_modules',
];
module.exports = {
devtool: 'inline-source-map',
entry: {},
module: {
noParse: [
/node_modules(\\|\/)sinon/,
/node_modules(\\|\/)acorn/,
],
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.css$/, loader: 'null-loader' },
{ test: /\.scss$/, exclude: /node_modules/, loaders: ['style-loader', 'css-loader', 'sass-loader'] },
{ test: /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
loader: 'imports?define=>false,require=>false',
},
{ test: /\.js$/,
loader: 'babel-loader',
exclude: [/node_modules/],
},
{ test: /\.jpe?g$|\.gif$|\.png$|\.svg$/i,
loader: 'null-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
new webpack.LoaderOptionsPlugin({
options: {
context: path.resolve(process.cwd()),
eslint: {
configFile: '.eslintrc'
},
sassLoader: {
includePaths: [
path.join(__dirname, '../../', 'node_modules/ui-components/src/styles/ui-styles/assets')
]
}
},
}),
],
node: {
fs: 'empty',
child_process: 'empty',
net: 'empty',
tls: 'empty',
},
// required for enzyme to work properly
externals: {
jsdom: 'window',
'react/addons': 'react/addons',
'react/lib/ExecutionEnvironment': 'react/lib/ExecutionEnvironment',
'react/lib/ReactContext': 'window',
},
resolve: {
modules,
alias: {
// required for enzyme to work properly
sinon: 'sinon/pkg/sinon',
},
},
};
任何帮助或建议都会非常感激,因为我正在失去理智。感谢。