-
Notifications
You must be signed in to change notification settings - Fork 87
Usage with Babel 7 #253
Comments
Hah, thanks for reading my tutorial 😉
You don't have to specify |
I'm trying to user this plugin with Rollup and Babel7. But I'm getting the following error in the console:
I'm running Rollup from the command line as an NPM script: "scripts: {
"bundle": "rollup -c"
} My .babelrc file: {
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
],
"plugins": [
"@babel/plugin-external-helpers",
"@babel/plugin-transform-parameters"
]
} And my rollup.config.js: import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'
import minify from 'rollup-plugin-babel-minify'
export default {
input: 'index.js',
output: {
file: 'dist/composi.js',
format: 'umd',
name: 'composi',
sourcemap: true,
sourcemapFile: 'dist/composi.js.map'
},
plugins:
[
babel({
exclude: 'node_modules/**'
}),
resolve({
jsnext: true,
main: true,
browser: true
}),
commonjs(),
minify({
mangle: { topLevel: true }
})
]
} What do I need to change to make it work with Babel? |
@rbiggs hard to tell without more info, could u paste in your package.json contents? and of course the stack trace of thrown error would be super nice |
package.json: {
"name": "composi",
"version": "1.0.0",
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
"main": "index.js",
"scripts": {
"bundle": "rollup -c",
"build": "npm run format && npm run lint && npm run bundle && gzip dist/composi.js",
"checkjs": "tsc --allowJs --checkJs --noEmit --moduleResolution node --target ES6 src/*.js",
"test": "browser-sync . --index test/index.html",
"format": "prettier --no-semi --single-quote --write ./src/*.js",
"lint": "eslint --config ./.eslintrc.json src"
},
"repository": {
"type": "git",
"url": "git+https://github.com/composor/composi.git"
},
"keywords": [
"angular",
"component",
"composi",
"frontend",
"hybrid",
"hyperscript",
"jsx",
"library",
"progressive web app",
"pwa",
"react",
"vuejs",
"virtual dom"
],
"author": "Robert Biggs",
"license": "MIT",
"bugs": {
"url": "https://github.com/composor/composi/issues"
},
"homepage": "https://github.com/composor/composi#readme",
"devDependencies": {
"@babel/core": "^7.0.1",
"@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.1.0",
"@babel/preset-env": "^7.0.0",
"@composi/get-type": "^1.0.0",
"@composi/merge": "^1.0.0",
"eslint": "^4.19.1",
"gzip-cli": "^0.1.3",
"prettier": "^1.13.7",
"rollup": "^0.65.2",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-babel-minify": "^6.0.0",
"rollup-plugin-commonjs": "^8.2.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-resolve": "0.0.1-predev.1",
"typescript": "^3.0.3"
}
} When I run
$: npm run build
> composi@1.0.0 build /Users/rbiggs/Github/@composi/core
> npm run format && npm run lint && npm run bundle && gzip dist/composi.js
> composi@1.0.0 format /Users/rbiggs/Github/@composi/core
> prettier --no-semi --single-quote --write ./src/*.js
src/constants.js 74ms
src/h.js 29ms
src/render.js 8ms
src/unmount.js 10ms
src/vdom.js 91ms
src/vnode.js 19ms
> composi@1.0.0 lint /Users/rbiggs/Github/@composi/core
> eslint --config ./.eslintrc.json src
> composi@1.0.0 bundle /Users/rbiggs/Github/@composi/core
> rollup -c
index.js → dist/composi.js...
[!] (babel plugin) Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
index.js
Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
at throwVersionError (/Users/rbiggs/Github/@composi/core/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
at Object.assertVersion (/Users/rbiggs/Github/@composi/core/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
at _default (/Users/rbiggs/Github/@composi/core/node_modules/@babel/plugin-external-helpers/lib/index.js:29:7)
at /Users/rbiggs/Github/@composi/core/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at Function.memoisePluginContainer (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
at Function.normalisePlugin (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
at /Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/rbiggs/Github/@composi/core/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at /Users/rbiggs/Github/@composi/core/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:57:26
at Object.transform$1 (/Users/rbiggs/Github/@composi/core/node_modules/rollup-plugin-babel/dist/rollup-plugin-babel.cjs.js:141:18)
at /Users/rbiggs/Github/@composi/core/node_modules/rollup/dist/rollup.js:20831:25
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! composi@1.0.0 bundle: `rollup -c`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the composi@1.0.0 bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rbiggs/.npm/_logs/2018-09-18T18_31_19_127Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! composi@1.0.0 build: `npm run format && npm run lint && npm run bundle && gzip dist/composi.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the composi@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rbiggs/.npm/_logs/2018-09-18T18_31_19_206Z-debug.log |
If I leave out |
From the looks of your |
Yeah, that's right - please report back when u upgrade |
OK, so doing an npm install --save-dev only installs 3.0.7. with @latest I got 4.0.3. Using that I get this error: index.js → dist/composi.js...
[!] (babel plugin) Error: Cannot find module '@babel/preset-env' from '/Users/rbiggs/Github/@composi/core'
index.js
Error: Cannot find module '@babel/preset-env' from '/Users/rbiggs/Github/@composi/core'
at Function.module.exports [as sync] (/Users/rbiggs/Github/@composi/core/node_modules/resolve/lib/sync.js:43:15)
at resolveStandardizedName (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
at items.map (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (/Users/rbiggs/Github/@composi/core/node_modules/@babel/core/lib/config/config-descriptors.js:47:19) Seems to be having problems with @babel scoped packages. |
Could u try removing & reinstalling your node_modules completely? Or maybe you could share your repository? Would help a lot in solving this quicker. |
Let me see about making a smaller, reduced trial repo. Will be less to troubleshoot. |
For what its worth, I had this same issue with jest and babel@7. The solution was to install |
I made a simpler project and, surprise that worked. So I used that as the base for the complex project, adding everything in piece by piece and that compiles as expected. So closing this. |
Thanks for reporting back. I consider this issue closed, if you have any other issues please open a new one. |
install "@babel/core": "^7.1.0" |
I have 7.1.2 and the issue still exists so that won't help. Btw the bridge package is just a workaround, I wouldn't consider this issue as resolved... |
@wintercounter you have to share a repository with the issue reproduced to get some help, without it I won't be able to tell you what's the problem in your case |
Many of the fix comments above for the error ("[!] (babel plugin) Error: Cannot find module '@babel/preset-env' from ...") are not necessary if using the 'babel-upgrade' tool. Working with npm, i used the 'npx babel-upgrade --write --install' command to do entire Babel 7 upgrade. THEN, to fix the Error message for ( [!] (babel plugin) Error: Cannot find module '@babel/preset-env' from ..."), because I am also using Rollup with this build...From the ROOT Directory, I then went to the Rollup configuration file that handles babel's options (there should only be a few of these to look thru to find the right one on your build). **One way to find the correct rollup file with your build's Babel options, is to look inside the 'rollup.config.js' file and probably at the very top you will see UMD modules get imported from another file. It is that other file where pulling 'from' that you then want to find. Once you find the correct Rollup file within the root dir that is managing your Babel options..then just update the babel option for the 'presets' to "@babel/preset-env". And now all is good! Mine looks like this:
|
I have a question in regards of using this with Babel 7.
If I'm using a
.babelrc.js
do I need to set@babel/env
options to{loose: true, modules: false }
?What about setting
cjs && 'transform-es2015-modules-commonjs'
? Is this still needed for Babel 7?I'm trying to follow this tutorial if it helps.
The text was updated successfully, but these errors were encountered: