使用Webpack 1.13(ReactJS)导出意外的令牌

时间:2018-05-09 08:16:53

标签: reactjs webpack babeljs

我是webpack& babel编译我的反应应用程序。 在配置中,我有

(抱歉,由于代码过多,我不得不在jsfiddle中添加它: https://jsfiddle.net/tu5nnq7L/

和里面:

public class LogFile
    {
        public List<string> Contents { get; }
        string _fullPath;
        long position;

        public LogFile(string fullPath)
        {
            if (File.Exists(fullPath))
            {
                _fullPath = fullPath;
                Contents = new List<string>();
                Read();
            }
            else
            {
                throw new FileNotFoundException($"{fullPath} not found");
            }
        }


        public void Read(FileSystemWatcher fsw = null)
        {
            if (fsw != null)
                fsw.EnableRaisingEvents = false; //set to false to prevent Changed event be fired twice

            FileStream fs = null;
            StreamReader sr = null;

            try
            {
                fs = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                try
                {
                    sr = new StreamReader(fs, Encoding.UTF8);
                    if (Contents.Count == 0)
                    {
                        Debug.WriteLine($"Initial read");
                        AddToContents(_fullPath, sr);
                        position = fs.Length; //store the length of the stream
                    }
                    else
                    {
                        sr.DiscardBufferedData();
                        sr.BaseStream.Seek(position, SeekOrigin.Begin);
                        AddToContents(_fullPath, sr);
                        position = fs.Length; //store the length of the stream
                    }

                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Error while reading from {_fullPath}");
                    //log exception 
                }
                finally
                {
                    if (sr != null)
                        sr.Close();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error while opening {_fullPath}");
                //log exception 
            }
            finally
            {
                if (fs != null)
                    fs.Close();
                if (fsw != null)
                    fsw.EnableRaisingEvents = true; //set raise events for the filesystemwatcher to true 
            }
        }

        private List<string> AddToContents(string fullPath, StreamReader sr)
        {
            List<string> newLines = new List<string>();
            try
            {
                while (!sr.EndOfStream)
                {
                    try
                    {
                        string line = sr.ReadLine();
                        if (line != string.Empty)
                        {
                            Contents.Add(line);
                            newLines.Add(line);
                            Debug.WriteLine(line);
                        }

                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine($"Error processing line in {fullPath}");
                        throw;
                    }
                }
                return newLines;

            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error while reading from {fullPath}");
                throw;
            }
        }
    }
    class Program
    {
        static LogFile file;
        static FileSystemWatcher fsw;
        static void Main(string[] args)
        {
            string path = @"C:\Temp\test.txt";
            file = new LogFile(path);
            CreateWatcher(path);
            Console.ReadKey();
        }

        private static FileSystemWatcher CreateWatcher(string fileNameFullPath)
        {
            fsw = new FileSystemWatcher(Path.GetDirectoryName(fileNameFullPath)); //constructor only accepts directory path
            fsw.IncludeSubdirectories = false;
            fsw.Filter = Path.GetFileName(fileNameFullPath); //filter for the given file 
            fsw.NotifyFilter = NotifyFilters.LastWrite;
            fsw.EnableRaisingEvents = true;
            fsw.Changed += Fsw_Changed;
            return fsw;
        }

        private static void Fsw_Changed(object sender, FileSystemEventArgs e)
        {
            if (file != null)
                file.Read(fsw);
        }
    }

但是在简单的export var声明中,我有这个错误: 未捕获的SyntaxError:意外的令牌导出

{
  "presets": [
    ["env", {
      "targets": {
        "chrome": 52,
        "browsers": ["last 10 versions", "safari 7"]
      }
    }]
  ],
  "plugins": ["transform-object-rest-spread"]
}

(与导入*相同,来自'../constants/Types'的类型)

我不明白为什么我有这个错误。谁可以解释一下?

谢谢。

0 个答案:

没有答案