Posts

Showing posts with the label Babeljs

Cannot Import .tsx File From .ts File (and Vice Versa)

Answer : When you write import WriteEditor from './write_editor'; Webpack will automatically look for ./write_editor ./write_editor.js ./write_editor.json (And a few others) Since you're using .ts and .tsx , you need to tell it to look for those too in your Webpack config using resolve.extensions : { resolve: { extensions: [".js", ".json", ".ts", ".tsx"], }, } In my case, I got same error when using typescript-eslint . It is an app created by create-react-app . The way is by adding this code in .eslintrc.js . module.exports = { // ... settings: { 'import/resolver': { 'node': { 'extensions': ['.js','.jsx','.ts','.tsx'] } } } };

Babel 7 - ReferenceError: RegeneratorRuntime Is Not Defined

Answer : Updated Answer: If you are using Babel 7.4.0 or newer, then @babel/polyfill has been deprecated. Instead, you will want to use the following at the top of your main js file (likely index.js or similar): import "core-js/stable"; import "regenerator-runtime/runtime"; Install these packages either with npm: npm install --save core-js npm install --save regenerator-runtime or with yarn: yarn add core-js yarn add regenerator-runtime Original Answer: I just encountered this problem and came across the following solution: In package.json I had @babel/polyfill as a dependency. However, in my index.js (My main js file) I had neglected to place the following line at the the top: import '@babel/polyfill' Once I imported it, everything worked fine. I did not need to install babel-runtime as other answers are suggesting. There is already a very good answer here (originally posted on the Babel6 question) which I will just translate to Yarn. ...

Babel-jest Doesn't Handle ES6 Within Modules

Answer : By default any code in node_modules is ignored by babel-jest , see the Jest config option transformIgnorePatterns . I've also created a PR on your example repo, so you can see it working. While this works, I've found it to be extremely slow in real applications that have a lot of dependencies containing ES modules. The Jest codebase has a slightly different approach to this as you can find in "babel-jest transforming dependencies" (sorry, won't let me post more than 2 URLs) . This can also take much longer on Windows, see "Taking 10 seconds on an empty repo" . If doing "unit" testing, mocking is probably the better way to go. You could try adding the transform-es2015-modules-commonjs plugin to your babel config file for testing only. Here is an example config file which tells babel to transpile modules only when in a testing environment. You can put it underneath your presets: { "presets": [ "react...