insin / nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Other
5.57k stars 331 forks source link

babel-preset-env not polyfill on demand for IE11 #268

Closed KatSick closed 7 years ago

KatSick commented 7 years ago

This issue is a: Question / support request Which modules are installed in your project?

swipecare-admin@1.3.2 /Users/ochervak/Projects/inferno-nwb
├── babel-eslint@7.1.1
├── classnames@2.2.5
├── compression@1.6.2
├── connect-history-api-fallback@1.3.0
├── core-js@2.4.1
├── eslint@3.15.0
├── eslint-plugin-react@6.10.0
├── http-proxy-middleware@0.17.3
├── i18next@7.0.0
├── i18next-browser-languagedetector@1.0.1
├── is-personnummer@1.1.1
├── mobx@3.1.0
├── mobx-react@4.1.0
├── mobx-utils@2.0.1
├── moment@2.17.1
├── node-pre-gyp@0.6.32 extraneous
├── nwb@0.15.6
├── nwb-sass@0.7.1
├── react@15.4.2
├── react-addons-shallow-compare@15.4.2
├── react-copy-to-clipboard@4.2.3
├── react-dom@15.4.2
├── react-maskedinput@3.3.4
├── react-notification-system@0.2.11
├── react-router@3.0.2
├── react-router-scroll@0.4.1
├── react-select@1.0.0-rc.3
├── react-spinkit@2.0.0
├── react-tooltip@3.2.7
├── reactabular-table@8.6.0
├── serializr@1.1.9
└── table-resolver@3.1.0

Which versions of Node.js, npm and nwb are you using (if using it globally)?

→ node -v
npm -v
nwb -v
v7.4.0
4.0.5
v0.15.6

My NWB config is:

const path = require('path');

const isDev = process.env.NODE_ENV === 'development';

module.exports = {
  type: 'react-app',
  babel: { runtime: true },
  webpack: {
    aliases: {
      pages: path.resolve('src/pages'),
      components: path.resolve('src/components'),
      formatters: path.resolve('src/formatters'),
      models: path.resolve('src/stores/models'),
      stores: path.resolve('src/stores'),
      services: path.resolve('src/services'),
      utils: path.resolve('src/utils'),
      assets: path.resolve('src/assets')
    },
    extractText: {
      allChunks: !isDev
    },
    compat: {
      moment: {
        locales: ['en', 'sv']
      }
    }
  }
};

I have some code with 'abc'.includes('b') and in IE11 i receive:

TypeError: Object doesn't support property or method 'includes'

As far as i understand runtime: true should polyfill all methods on demand. Is it correct ?

insin commented 7 years ago

The runtime transform doesn't deal with instance methods, this is from its docs:

NOTE: Instance methods such as "foobar".includes("foo") will not work since that would require modification of existing builtins (Use babel-polyfill for that).

You would need handle polyfilling String.prototype.includes() yourself.

KatSick commented 7 years ago

Many thanks