rollup-plugin-polyfill-node icon indicating copy to clipboard operation
rollup-plugin-polyfill-node copied to clipboard

Does process.cwd() work?

Open gavinmcfarland opened this issue 4 years ago • 4 comments

Hi, you might already be aware of this. I can't get process.cwd() to work and I'm not sure if there is a missing option I need to pass in for it to work. I can see that it exists in the source code. I think this is probably an issue from rollup-plugin-node-polyfills because it doesn't work in that either.

After setting up rollup and the required plugins it doesn't polyfill process.cwd().

// rollup.config.js

import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import nodePolyfills from 'rollup-plugin-polyfill-node';


export default [{
    input: 'src/index.ts',
    output: {
        file: 'dist/index.js',
        format: 'cjs',
        name: 'code'
    },
    plugins: [
        typescript(),
        nodePolyfills(),
        commonjs()
    ]
}];
// src/index.ts

console.log(process.cwd())
// dist/index.js

'use strict';

console.log(process.cwd());

gavinmcfarland avatar Mar 19 '21 18:03 gavinmcfarland

This plugin only polyfills node native modules, not globals

remorses avatar Mar 26 '21 12:03 remorses

Hi @remorses, so just to confirm it doesn't polyfill process? Because the readme suggests it does.

gavinmcfarland avatar Mar 26 '21 14:03 gavinmcfarland

Hi @gavinmcfarland - did you get anywhere with this? facing the same issue

mattrhysgregory avatar May 05 '22 08:05 mattrhysgregory

It was a while since I looked at it, but I think I did get it working, I remember something about the documentation being hard to understand.

I might have done...

export default [{
    // ...
    plugins: [
        typescript(),
        nodePolyfills({ include: null}),
        commonjs()
    ]
}];

Or I might have passed in {process: true}. The original repo suggests you can turn individual built-ins on and off. https://github.com/ionic-team/rollup-plugin-node-polyfills

gavinmcfarland avatar May 06 '22 00:05 gavinmcfarland