相关疑难解决方法(0)

Can't import npm modules in commonjs with rollup : "require is not defined"

I work on an ES6 project that I transpile using rollup and babel. It works well except when I try to import npm modules that use commonjs (and particularly require('something')) getting an error "require is not defined" in my browser (which means it hasn't properly compiled node modules from commonjs to ES5). However, I use rollup-plugin-node-resolve and rollup-plugin-commonjs, that should do that job if I've understood properly...

Here are my rollup config file:

import babel from 'rollup-plugin-babel';
import eslint …
Run Code Online (Sandbox Code Playgroud)

javascript rollup commonjs node.js ecmascript-6

5
推荐指数
1
解决办法
3099
查看次数

将旧版 Require 模块与 Rollup 一起使用

我认为 commonjs 插件可以让您使用较旧的模块,但我无法让 rollup 与https://www.npmjs.com/package/create-hmac一起使用。这是一个较旧的模块,据我所知我需要使用:

const createHmac = require("create-hmac");

我无法使用导入。有什么方法可以将其与汇总一起使用,还是我运气不好?我正在使用标准的 Svelte rollup 模板,并尝试使用namedExports、dynamicRequireTargets、不同的 Resolve 设置等。如果任何真正了解 rollup 的人可以帮助我,我将不胜感激!

hmac rollupjs svelte

1
推荐指数
1
解决办法
1322
查看次数

标签 统计

commonjs ×1

ecmascript-6 ×1

hmac ×1

javascript ×1

node.js ×1

rollup ×1

rollupjs ×1

svelte ×1