GithubHelp home page GithubHelp logo

sindresorhus / import-cwd Goto Github PK

View Code? Open in Web Editor NEW
53.0 6.0 5.0 11 KB

Import a module like with `require()` but from the current working directory

License: MIT License

JavaScript 87.96% TypeScript 12.04%

import-cwd's Introduction

import-cwd

Import a module like with require() but from the current working directory

Install

$ npm install import-cwd

Usage

const importCwd = require('import-cwd');

// Target module is at '/Users/sindresorhus/unicorn/foo.js'

console.log(__dirname);
//=> '/Users/sindresorhus/rainbow'

console.log(process.cwd());
//=> '/Users/sindresorhus/unicorn'

const foo = importCwd('./foo');

API

importCwd(moduleId)

Like require(), throws when the module can't be found.

importCwd.silent(moduleId)

Returns undefined instead of throwing when the module can't be found.

moduleId

Type: string

What you would use in require().

Related

  • import-from - Import a module from a given path
  • resolve-from - Resolve the path of a module from a given path
  • resolve-cwd - Resolve the path of a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • import-lazy - Import modules lazily
  • import-global - Import a globally installed module

License

MIT ยฉ Sindre Sorhus

import-cwd's People

Contributors

bendingbender avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

import-cwd's Issues

Does this work with ESM?

I'm trying to use import-cwd with eslint and I think they have moved to ESM on their newest release ๐Ÿค”

When I try to import-cwd I get the following error:

/Users/mansona/git/projects/lint-to-the-future/lint-to-the-future-eslint/node_modules/esm/esm.js:1
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/mansona/git/qonto/qonto-js/node_modules/@eslint/eslintrc/universal.js
require() of ES modules is not supported.
require() of /Users/mansona/git/qonto/qonto-js/node_modules/@eslint/eslintrc/universal.js from /Users/mansona/git/qonto/qonto-js/node_modules/eslint/lib/linter/linter.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename universal.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/mansona/git/qonto/qonto-js/node_modules/@eslint/eslintrc/package.json.

It could be because I'm using the esm module but I'm not sure why it was working before and suddenly stopped working ๐Ÿค”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.