这时我什至没有在寻找解决方案,只是很好奇为什么我的正则表达式可以在Firefox,Chrome和regex测试器中使用,而不能在Node 8.12、10.11和10.12中使用。
这里是:
var str = `import {User} from '..';
import {UserRole} from '..';
export class ServerUser {
_id?: string;
id?: string;
userRole?: string;
firstName?: string;
lastName?: string;
description?: string;
email?: string;
telephone?: string;
profileImg?: string;
dateOfBirth?: number;
registeredAt?: number;
isMale?: boolean;
password?: string;
username?: string;
media?: any[];
/**
* call this method to map the User to ServerUser
*
* @param {} user
* @returns {ServerUser}
*/
static map(user: User): ServerUser {
const u = {} as ServerUser;
[...etc.]
`;
var resultArray = str.match(/\s*[_u]id\?\:\sstring\;\s+([.\w\?\:\,\;\[\]\{\}\s]*)\;\n/m);
console.log(resultArray);
document.write(JSON.stringify(resultArray, null, 4));
在节点中,使用相同的正则表达式,如下所示:
fs.readFile(serverPath, 'utf8', (err1, serverContent) => {
if (err1) return resolve(false);
const serverPropArray = serverContent.match(/\s*[_u]id\?\:\sstring\;\s+([.\w\?\:\,\;\[\]\{\}\s]*)\;\n/m)[1].split(';').map( el => el.trim() );
引发错误:
...\gulpfile.js:383
const serverPropArray = serverContent.match(/\s*[_u]id\?\:\sstring\;\s+[.\w\?\:\,\;\[\]\{\}\s]*\;\n/m)[1].split(';').map( el => el.trim() );
^
TypeError: Cannot read property '1' of null
at fs.readFile (C:\wink\winkular-cli\gulpfile.js:383:127)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
有人吗?
答案 0 :(得分:0)