Babel file is copied without being transformed

前端 未结 10 2162
礼貌的吻别
礼貌的吻别 2020-11-22 06:09

I have this code:

\"use strict\";

import browserSync from \"browser-sync\";
import httpProxy from \"http-proxy\";

let proxy = httpProxy.createProxyServer({         


        
相关标签:
10条回答
  • 2020-11-22 06:52

    Same error, different cause:

    Transpiling had worked before and then suddenly stopped working, with files simply being copied as is.

    Turns out I opened the .babelrc at some point and Windows decided to append .txt to the filename. Now that .babelrc.txt wasn't recognized by babel. Removing the .txt suffix fixed that.

    0 讨论(0)
  • 2020-11-22 06:54

    Ultimate solution

    I wasted 3 days on this

    import react from 'react' unexpected identifier
    

    I tried modifying webpack.config.js and package.json files, and adding .babelrc, installing & updating packages via npm, I've visited many, many pages but nothing has worked.


    What worked? Two words: npm start. That's right.

    run the

    npm start 
    

    command in the terminal to launch a local server

    ...

    (mind that it might not work straight away but perhaps only after you do some work on npm because before trying this out I had deleted all the changes in those files and it worked, so after you're really done, treat it as your last resort)


    I found that info on this neat page. It's in Polish but feel free to use Google translate on it.

    0 讨论(0)
  • 2020-11-22 06:59

    In year 2018:

    Install following packages if you haven't yet:

    npm install babel-loader babel-preset-react
    

    webpack.config.js

    {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['es2015','react']  // <--- !`react` must be part of presets!
            }
          }
        ],
      }
    
    0 讨论(0)
  • 2020-11-22 07:02

    I had the same problem with a different cause:

    The code I was trying to load was not under the package directory, and Babel does not default to transpiling outside the package directory.

    I solved it by moving the imported code, but perhaps I could have also used some inclusion statement in the Babel configuration.

    0 讨论(0)
提交回复
热议问题