Imports from tsconfig paths not working with bazel: Cannot find module '#...' - node.js

Repo for reproduction: https://github.com/timothyaltemus/bazel-typescript-stackoverflow-example.
I am running into an issue where I am unable to use my tsconfig paths configuration for importing in my TypeScript files.
tsconfig.json:
{
...
"compilerOptions": {
"baseUrl": ".",
"paths" {
"#*": [
".",
"bazel-out/darwin-fastbuild/bin/*",
"bazel-out/k8-fastbuild/bin/*",
"bazel-out/x64_windows-fastbuild/bin/*",
"bazel-out/darwin-dbg/bin/*",
"bazel-out/k8-dbg/bin/*",
"bazel-out/x64_windows-dbg/bin/*"
]
},
"rootDirs": [
".",
"bazel-out/darwin-fastbuild/bin/",
"bazel-out/k8-fastbuild/bin/",
"bazel-out/x64_windows-fastbuild/bin/",
"bazel-out/darwin-dbg/bin/",
"bazel-out/k8-dbg/bin/",
"bazel-out/x64_windows-dbg/bin/"
]
...
}
...
}
Folder Structure:
apps
server
services
BUILD
hello_service.ts
BUILD
index.ts
libs
a_lib
BUILD
do_a.ts
b_lib
BUILD
do_b.ts
c_lib
BUILD
do_c.ts
Build
tsconfig.json
index.ts:
...
import { doToC } from '#libs/c_lib/do_c';
import {
HelloService,
HelloServiceImpl,
} from '#apps/server/services/hello_service';
...
Full Stacktrace:
INFO: Analyzed target //apps/server:server (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //apps/server:server up-to-date:
bazel-bin/apps/server/server.sh
bazel-bin/apps/server/server_loader.js
bazel-bin/apps/server/server_require_patch.js
INFO: Elapsed time: 1.994s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Error: Cannot find module '#libs/c_lib/do_c'
Require stack:
- /home/tim/.cache/bazel/_bazel_tim/4d04e993ef8ae996d277978eb4eab582/execroot/typescript/bazel-out/k8-fastbuild/bin/apps/server/server.sh.runfiles/typescript/apps/server/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (home/tim/.cache/bazel/_bazel_tim/4d04e993ef8ae996d277978eb4eab582/execroot/typescript/bazel-out/k8-fastbuild/bin/apps/apps/server/index.ts:4:1)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Please see the example repo for an example of how to reproduce this error.

Related

SVGO config file

With svgo 1.3.2 I used to run this command :
svgo --pretty --disable={removeUnusedNS,removeUselessDefs,removeUselessStrokeAndFill} file.svg -o file.min.svg
I updated to svgo 2.3.0 and now I get :
error: unknown option '--disable={removeUnusedNS,removeUselessDefs,removeUselessStrokeAndFill}'
So I tried to create a svgo.config.js like this :
const { extendDefaultPlugins } = require('svgo');
module.exports = {
plugins: extendDefaultPlugins([
{
name: 'removeUnusedNS',
active: false
},
{
name: 'removeUselessDefs',
active: false
},
{
name: 'removeUselessStrokeAndFill',
active: false
}
])
}
but I just get the error :
Error: Cannot find module 'svgo'
Require stack:
C:\Users\jpprade\Documents\vrac\svgo.config.js
C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\lib\svgo-node.js
C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\lib\svgo\coa.js
C:\Users\jpprade\AppData\Roaming\npm\node_modules\svgo\bin\svgo
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Module.require (internal/modules/cjs/loader.js:848:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (C:\Users\jpprade\Documents\vrac\svgo.config.js:1:34)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Module.require (internal/modules/cjs/loader.js:848:19)
svgo is install (globaly)
How can I run svgo with those 3 plugins disabled using to config file (or not) ?
Thanks !
What is the output when you run svgo -v?
It is possible that you are inside a project that has an older version as a dependency which takes precedence over the global svgo package.
You can try require using the absolute path to svgo 2.3.0.
For instance mine was like that require('/home/nili/.nvm/versions/node/v14.16.1/lib/node_modules/svgo');
I think it could also be in /usr/local/lib/node_modules/svgo if you installed it as root.

Semantic-release - Error: Cannot find module '../output'

No matter what I do I always get exactly the same error when I run command 'npx semantic-release --debug
' in BitBucket pipelines. Dry-run seems to run fine.
Thing I have already tried:
reinstall node modules
update packages
copy exactly the same configuration/packages from project with
working semantic-release
All the files are definitely there. Maybe it can't access?
here is a full debug report:
npx: installed 746 in 16.856s
[5:36:26 PM] [semantic-release] › ℹ Running semantic-release version 17.1.1
2020-06-25T17:36:26.883Z semantic-release:config load config from: /opt/atlassian/pipelines/agent/build/package.json
2020-06-25T17:36:26.887Z semantic-release:config options values: {
branches: [ 'master', 'develop' ],
repositoryUrl: 'git#$NEXUS_USERNAME.org:acurable/acupebble-g2-firmware.git',
tagFormat: 'v${version}',
plugins: [
[ '#semantic-release/commit-analyzer', [Object] ],
[ '#semantic-release/npm', [Object] ],
[ '#semantic-release/release-notes-generator', [Object] ],
'#semantic-release/changelog',
'#semantic-release/git'
],
_: [],
debug: true,
'$0': '/root/.npm/_npx/52/bin/semantic-release'
}
[5:36:27 PM] [semantic-release] › ✖ An error occurred while running semantic-release: Error: Cannot find module '../output'
Require stack:
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
at Function.Module._load (internal/modules/cjs/loader.js:835:27)
at Module.require (internal/modules/cjs/loader.js:1012:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Module.require (internal/modules/cjs/loader.js:1012:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js'
]
}
Error: Cannot find module '../output'
Require stack:
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
at Function.Module._load (internal/modules/cjs/loader.js:835:27)
at Module.require (internal/modules/cjs/loader.js:1012:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Module.require (internal/modules/cjs/loader.js:1012:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js'
]
2020-06-25T17:36:27.964997083Z stderr P }
This is crazy.
Just realised that I had this line in gitIgnore.txt: **/Output
In my local repository all the files were there but index.js was missing since all files in any **/Output path would not be included.
Will never use global gitIgnore again.

The "amdefine" can not load a custom module

I installed the requirejs package to optimize the work with paths to files. In general, I do the next steps:
I have an object with paths to file, that have next values:
"app/database": "/home/dmitry/projects/information-platform-api/app/utils/database"
After I initialize the requirejs mapping in app.js (main file):
requirejs.config({
baseUrl: __dirname,
nodeRequire: require,
paths: paths,
map: {
'*': paths
}
});
After, I need to initialize base models, and with help for I called all files from paths object. This looks like:
for (let file in paths) {
requirejs(paths[file]);
}
When I initializing the file, which has the dependency of the above "app/database", I have a message error: Error: Cannot find module 'app/database'.
Maybe, I don't understand "How works the amdefine", but I have opinion, what a requirejs and amdefine don`t link. Do you have any ideas, why it doesn't work?
A part of the file, which need to investigate:
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
define([
'sequelize',
'app/database',
'model/student'
], (
Sequelize,
sequelize,
Student
) => { });
Result of my investigation:
The amdefine doesn't know about requirejs mapping.
Full error message:
Error: Tried loading "/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company" at /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company then tried node's require("/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company") and it failed with error: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2600:27
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39)
at Function.req.get (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2524:33)
at Object.localRequire [as require] (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1678:40)
at requirejs (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2047:24)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app.js:142:5)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/bin/www:7:13)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
originalError: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at req (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:144:31)
at stringRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:220:28)
at amdRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:113:24)
at /home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:177:24
at Array.map (<anonymous>)
at runFactory (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:176:25)
at define (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:277:13)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js:5:1)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2598:75
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js',
'/home/dmitry/projects/information-platform-api/app.js',
'/home/dmitry/projects/information-platform-api/bin/www'
]
},
moduleName: '/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company',
requireModules: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company'
]
}
Process finished with exit code 1
The solution is here guys. The amdefine have two params, first param it's a global variable module, and the second it's require function for calling the local files. By default, it was just require not requirejs which contains custom mapping.
if (typeof define !== 'function') {
var define = require('amdefine')(module, require('requirejs'));
}

AWS Lambda Node.js 6.10 : "errorMessage": "Cannot find module 'cfn-response'",

I am trying to deploy a lambda function in Nodejs 6.10 and I am getting this error:
Response:
{
"errorMessage": "Cannot find module 'cfn-response'",
"errorType": "Error",
"stackTrace": [
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)",
"Object. (/var/task/index.js:2:20)",
"Module._compile (module.js:570:32)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)"
]
}
Function Logs:
START RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8 Version: $LATEST
Unable to import module 'index': Error
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/index.js:2:20)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
END RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8
REPORT RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8 Duration: 87.34 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 32 MB
I am using Node.js 6.10 version for this method and did inline code edit.
Code I am trying to execute:
var response = require('cfn-response');
exports.handler = function(event, context) {
var input = parseInt(event.ResourceProperties.Input);
var responseData = {Value: input * 5};
response.send(event, context, response.SUCCESS, responseData);
};
Any clues?
Mostly it is because of the way zipping the files making the problem. Instead of zipping the root folder you have to select all files and zip it like below,
Please upload all files and subfolders like below. Please include node_modules folder as well in the zip.

Grunt reference error

Gruntfile.js
module.exports = functions(grunt)
{
grunt.initConfig({
//pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';',
},
dist: {
src: ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md'],
dest: 'APIdocu/ConcatApis.md',
//files: {
//'APIdocu/NewApi.md' : ['APIdocu/AccountsCollection.md', 'APIdocu/AccountsFollowersCollection.md']
},
},
});
grunt.loadNpmTasks('grunt-contrib-concat');
//tasks
grunt.registerTask('default', ["concat"]);
}
error message
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Loading "Gruntfile.js" tasks...ERROR
ReferenceError: grunt is not defined
at Object.<anonymous> (C:\Users\gs1460\Desktop\Markdownfiles\apis\Gruntfile.js:1:90)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at loadTask (C:\Users\gs1460Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:323:10)
at Task.task.init (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\task.js:437:5)
at Object.grunt.tasks (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt.js:120:8)
at Object.module.exports [as cli] (C:\Users\gs1460\Desktop\Markdownfiles\apis\node_modules\grunt\lib\grunt\cli.js:38:9)
Running tasks: concat:dist
Warning: Task "concat:dist" not found. Use --force to continue.
Aborted due to warnings.
How do I get rid of this error.
I need to concatenate md files to one.It gives me the above error. Tried changing the code many times. But same issue. Can you help in this.
Probably the problem is that you are writting functions instead of function.
Check also if the variable grunt is in the correct scope. And please use tabs correctly!
module.exports = function(grunt)
Regards.

Resources