charting-library-examples icon indicating copy to clipboard operation
charting-library-examples copied to clipboard

vue + Nuxtjs2 Cant import charting_library.min

Open FF-ru opened this issue 5 years ago • 8 comments

trying to include charting_library

let { widget } = require('~/assets/js/charting_library.min')

it throws: Uncaught TypeError: Cannot read property 'TradingView' of undefined

screenshot 2019-01-25 at 12 55 03

FF-ru avatar Jan 25 '19 05:01 FF-ru

What bundler you use? It looks it doesn't support UMD modules.

timocov avatar Jan 28 '19 12:01 timocov

nuxt2 exists webpack4.26.1 it worked fine with webpack3 on nuxtjs

FF-ru avatar Jan 29 '19 09:01 FF-ru

just tried to assemble with clean webpack4.26.1 without vuejs and nuxtjs so it works. I have no idea

FF-ru avatar Jan 30 '19 14:01 FF-ru

I would suggest you check webpack's config you use to bundle your app.

timocov avatar Jan 30 '19 16:01 timocov

same with vuejs .-.

huuhait avatar Mar 12 '19 19:03 huuhait

@FF-ru adding modules: 'commonjs' to the build.babel.presets fix this issue

For example:

babel: {
    presets({ isServer }) {
      return [
        [
          require.resolve('@nuxt/babel-preset-app'),
          {
            //targets: isServer ? { node: '10' } : { ie: '11' },
            //corejs: { version: 3 },
            modules: 'commonjs'
          }
        ]
      ]
    }
  }

mahapo avatar Apr 15 '19 16:04 mahapo

For vue this should work:

babel: {
    presets: [
      [
        '@babel/env',
        {
          //targets: {
          //  node: 'current'
          //},
          modules: 'commonjs'
        }
      ]
    ]
  }

mahapo avatar Apr 15 '19 16:04 mahapo

https://github.com/tradingview/charting-library-examples/issues/170#issuecomment-745245792 I hope this will help

ShadiSimplbit avatar Dec 16 '20 08:12 ShadiSimplbit