Closed neeeeecka closed 5 years ago
For that you need https://github.com/rollup/rollup-plugin-node-resolve
@Andarist Thank you so much, that is what I need, but how do I use it in my build.js file? Currently if I try to import resolve from "rollup-plugin-node-resolve";
I get
(function (exports, require, module, __filename, __dirname) { import resolve from "rollup-plugin-node-resolve";
^^^^^^
SyntaxError: Unexpected token import
this error.
From what I see you are using require
in that build.js file - so just require it, similarly to what you do with rollup-plugin-babel
@Andarist, sorry for bothering you so much.
I included this plugin as const resolve = require("rollup-plugin-node-resolve");
, then in plugins[]
i passed:
resolve({
browser: true,
modulesOnly: true
}),
Now I get another error:
.buildStart is not a valid Plugin property
You'd have to share your repository with the issue reproduced in it - without that, I can't quite help you more. It seems like maybe some rollup vs plugins compatibility issue. Please check if you are using the latest versions of everything.
@Andarist here, https://github.com/blackstormx/neoglass.ge, checked versions, everything seems to be latest. Installed every plugin and library today.
I've fixed your script (you've tried to pass rollup-plugin-node-resolve
to Babel instead of to Rolluo):
const resolve = require("rollup-plugin-node-resolve");
const commonjs = require("rollup-plugin-commonjs");
require("rollup")
.rollup({
input: "./_jsSrc/boug2.js",
plugins: [
resolve(),
require("rollup-plugin-babel")({
exclude: "node_modules/**",
presets: ["@babel/preset-env"],
runtimeHelpers: true,
plugins: [
// "@babel/external-helpers",
"@babel/plugin-proposal-class-properties",
["@babel/transform-runtime", { useESModules: true }]
]
}),
commonjs(),
]
})
.then(bundle => {
bundle
.generate({
format: "iife",
name: "mainModule"
})
.then(function(result) {
require("fs").writeFileSync(
"./_jsBuild/bundle.js",
result.output[0].code
);
});
})
.then(null, err => console.error(err));
Had to install rollup-plugin-commonjs
too.
@Andarist Thank you very much! You solved my issue and made my day!
Bug Report
Current Behavior During build, I am getting errors:
etc... My package .json:
And a part of a build script:
if I disable core.js3 plug-in, and manually try to import library from node_modules from inside my app's source code using
import {something} from "../../node_modules/bla/bla/"
Into my source code, it still doesn't work. Same error. Can't resolve. Also corejs has nothing to do with it because I also have tried using @babel-transform-runtime.But if I provide plugins into rollup like this:
(I provided them in externals array)
Then suddenly errors are disappearing one by one, because rollup loads these externals. But you know better than me that this is not how job is done. I am not going to list tens or hundreds of externals like this.
OS: windows 10
My file structure: ----node_modules ----jsBuild -------bundle.js ----jsSrc -------boug2.js(main src file) -------modules ----------module1 ----------module2 ----------.... ----tools -------build.js (I use it to bundle and transpile files using babel and rollup)
Thanks in advance.