Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'src'

notacorn

Let's say my app looks like this

├── index.js
└── src
    ├── do_foo.js

do_foo.js

function foo() {
    return "bar";
}

export default foo;

index.js

import foo from 'src/do_foo';

foo();

Running node index.js results in the following error

> node index.js

internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'src' imported from /mnt/c/Users/*******/Projects/*******/index.js
    at packageResolve (internal/modules/esm/resolve.js:620:9)
    at moduleResolve (internal/modules/esm/resolve.js:659:14)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:752:11)
    at Loader.resolve (internal/modules/esm/loader.js:97:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:50:40)
    at link (internal/modules/esm/module_job.js:49:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the *******@1.0.0 start 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!     /mnt/c/Users/*******/.npm/_logs/2020-07-21T03_38_34_404Z-debug.log

Seeing as I've managed to mess up at such an early point, the solution, I'd imagine, has to be pretty simple. What cardinal rule of javascript am I violating here?

I should add that I know everything will work if everything is in the same folder, but that's not what I'm aiming for. If at all possible, it's a better look to keep index.js in the outermost directory.

Edit: I want to clear up that my problem was NOT caused by a typo. My code was syntactically fine, it was the import that needed a relative scope. I mistyped something when I was writing the example code, that had nothing to do with the initial question.

Ashish Kumar Senapati

You must use the full file path to get this working.

import foo from './src/do_foo.js';

console.log(foo());

Since its an experimental feature, you will get this warning.

ExperimentalWarning: The ESM module loader is experimental.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/plugin-preset-react' imported from

From Dev

ERR_MODULE_NOT_FOUND: Cannot find Module Error

From Dev

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js

From Dev

Error: Cannot find module '../../package.json'

From Javascript

Gulp Error: Cannot find module 'jshint/src/cli'

From Dev

error "Cannot find module 'material-ui/src/navigation/close"

From

Golang - error `cannot find package`

From Dev

npm install error: cannot find module 'read-package-tree'

From Dev

Gitlab CI/CD: Cannot find module: 'src/css/index.css'. Make sure this package is installed

From Dev

ERROR in ./src/styles.scss .. Module build failed: Error: Cannot find module 'node-sass'

From Dev

error 'MODULE NOT FOUND', Cannot find module

From Dev

Error: Cannot find module './'

From

Endorsers Instantiate Chaincode with error "cannot find package"

From

Cannot find package "internal/cpu" error in GO

From

"cannot find package" error on godoc playable examples

From

Go: cannot find package "fmt" error

From Dev

maven error: cannot find symbol class in a package

From Dev

Vue.js Error "Cannot find module './undefined'" from webpack when using src=require()

From Dev

Getting Error: Cannot find module './src/init' when trying to initialize a react native app

From Dev

Error: Cannot find module '/usr/src/app/nodemon' while using docker-compose

From Dev

Cannot install nuget package - package not found error

From Dev

Angular 5: ERROR in src/app/app.module.ts(24,24): error TS2307: Cannot find module 'https'

From Dev

Getting Error: Error: Cannot find module 'src/core/configurations/configFunctions when executing "protractor ./conf.ts --suite homepage"

From Dev

npm ERR! Cannot find module './access-error.js'

From Dev

ERR_MODULE_NOT_FOUND

From

go mod: cannot find module providing package

From Dev

An issue with creating an npm package: 'Cannot find module ...'

From Dev

Cannot find module '../package.json'

From Dev

npm install error Cannot find module 'read-package-json.js'

Related Related

  1. 1

    Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/plugin-preset-react' imported from

  2. 2

    ERR_MODULE_NOT_FOUND: Cannot find Module Error

  3. 3

    Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js

  4. 4

    Error: Cannot find module '../../package.json'

  5. 5

    Gulp Error: Cannot find module 'jshint/src/cli'

  6. 6

    error "Cannot find module 'material-ui/src/navigation/close"

  7. 7

    Golang - error `cannot find package`

  8. 8

    npm install error: cannot find module 'read-package-tree'

  9. 9

    Gitlab CI/CD: Cannot find module: 'src/css/index.css'. Make sure this package is installed

  10. 10

    ERROR in ./src/styles.scss .. Module build failed: Error: Cannot find module 'node-sass'

  11. 11

    error 'MODULE NOT FOUND', Cannot find module

  12. 12

    Error: Cannot find module './'

  13. 13

    Endorsers Instantiate Chaincode with error "cannot find package"

  14. 14

    Cannot find package "internal/cpu" error in GO

  15. 15

    "cannot find package" error on godoc playable examples

  16. 16

    Go: cannot find package "fmt" error

  17. 17

    maven error: cannot find symbol class in a package

  18. 18

    Vue.js Error "Cannot find module './undefined'" from webpack when using src=require()

  19. 19

    Getting Error: Cannot find module './src/init' when trying to initialize a react native app

  20. 20

    Error: Cannot find module '/usr/src/app/nodemon' while using docker-compose

  21. 21

    Cannot install nuget package - package not found error

  22. 22

    Angular 5: ERROR in src/app/app.module.ts(24,24): error TS2307: Cannot find module 'https'

  23. 23

    Getting Error: Error: Cannot find module 'src/core/configurations/configFunctions when executing "protractor ./conf.ts --suite homepage"

  24. 24

    npm ERR! Cannot find module './access-error.js'

  25. 25

    ERR_MODULE_NOT_FOUND

  26. 26

    go mod: cannot find module providing package

  27. 27

    An issue with creating an npm package: 'Cannot find module ...'

  28. 28

    Cannot find module '../package.json'

  29. 29

    npm install error Cannot find module 'read-package-json.js'

HotTag

Archive